Re: Problem with appendChild and ellipsis... [message #173099 is a reply to message #173077] |
Mon, 21 March 2011 08:26 |
alvaro.NOSPAMTHANX
Messages: 277 Registered: September 2010
Karma:
|
Senior Member |
|
|
El 20/03/2011 19:24, Dennis escribió/wrote:
> On Sun, 20 Mar 2011 13:14:29 -0400, Jerry Stuckle
> <jstucklex(at)attglobal(dot)net> wrote:
>
>> Can you post the actual code which is failing (or, if it's too long, a
>> complete example of the failure)?
>
> Here's a short sample that illustrates the problem...
>
> <?php
>
> foo();
> echo "test done<br>";
> exit;
>
> function foo()
> {
> $doc = new DOMDocument();
> $doc->formatOutput = true;
>
> $title = $doc->createElement("title");
> $doc->appendChild($title);
>
> $title_data = "Some data followed by an ellipses…";
>
> $title_text = $doc->createTextNode($title_data);
> $title->appendChild($title_text);
>
> $doc->saveXML();
> $doc->save("test.xml");
>
> echo "foo done<br>";
> }
>
> ?>
If I run this code I get this file:
<?xml version="1.0"?>
<title>Some data followed by an ellipses…</title>
.... where … is the entity for ellipsis.
My guess is that you are feeding createTextNode() with the wrong encoding:
http://es2.php.net/manual/en/intro.dom.php
«The DOM extension uses UTF-8 encoding. Use utf8_encode() and
utf8_decode() to work with texts in ISO-8859-1 encoding or Iconv for
other encodings. »
--
-- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
-- Mi sitio sobre programación web: http://borrame.com
-- Mi web de humor satinado: http://www.demogracia.com
--
|
|
|