#34730 [Bgs]: saveXML translates UTF-8 characters to entities

From: Date: Tue, 04 Oct 2005 13:14:15 +0000
Subject: #34730 [Bgs]: saveXML translates UTF-8 characters to entities
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-85997@lists.php.net to get a copy of this message
ID: 34730 User updated by: pesmail2003 at seznam dot cz Reported By: pesmail2003 at seznam dot cz Status: Bogus Bug Type: DOM XML related Operating System: Linux 2.6.10-5-i386 PHP Version: 5.0.5 New Comment: I'm sending updated test code. Plase don't throw this bugreport immediately away as "bogus". I really don't want to use this as support forum, and don't want to stupidly chat with developers. Maybe I sent bad example for the first time, but I'm trying to do what I can to help you to help me. Maybe we will find I'm dumb but maybe we will find and fix some problem together. Reproduce code -------------- <?php $xmlData = <<<XMLCODE <?xml version="1.0" encoding="utf-8"?> <test>"šèøžýáíé</test> XMLCODE; $dom = new DomDocument; $dom->loadXML( $xmlData ); echo $dom->saveXML($dom->firstChild); ?> Expected result --------------- <test>"ìšèøžýáíé</test> Actual result --------------- <test>"&#x161;&#x10D;&#x159;&#x17E;&#xFD;&#xE1;&#xED;&#xE9;</test> Previous Comments: ------------------------------------------------------------------------ [2005-10-04 15:02:15] derick@php.net Not without an example, but as this is not a user forum, please ask this kinds of questions on the php-general@lists.php.net mailinglist. ------------------------------------------------------------------------ [2005-10-04 14:57:50] pesmail2003 at seznam dot cz Thanks derick for fast response. But I found something interesting. When I set encoding in XML with <?xml version="1.0" encoding="UTF-8"?>, it works OK. But there is still no way to disable replacing special characters with entities when I have proper encoding and want to use saveXML with parameter "node" to save only part of the tree. Any solution to this? ------------------------------------------------------------------------ [2005-10-04 14:53:11] derick@php.net You need to specify the charset encoding in your XML, like so: <?php $xmlData = <<<XMLCODE <?xml version="1.0" encoding="utf8"?> <test>"привате</test> XMLCODE; $dom = new DomDocument; $dom->loadXML( $xmlData ); echo $dom->saveXML(); ?> ------------------------------------------------------------------------ [2005-10-04 14:46:19] pesmail2003 at seznam dot cz Description: ------------ saveXML function replaces UTF-8 characters to entities. If I have some UTF-8 characters in my loaded XML file and want to save it with saveXML, it replace everything to entities like this &#x10D; &#x159; &#x17E; &#xFD;&#xE1; &#xED; &#xE9; I had to write my own saveXML in PHP and it's really bad. Reproduce code: --------------- <?php $xmlData = <<<XMLCODE <?xml version="1.0" ?> <test>"ìšèøžýáíé</test> XMLCODE; $dom = new DomDocument; $dom->loadXML( $xmlData ); echo $dom->saveXML(); ?> Expected result: ---------------- <?xml version="1.0"?> <test>"ìšèøžýáíé</test> Actual result: -------------- <?xml version="1.0"?> <test>"&#x11B;&#x161;&#x10D;&#x159;&#x17E;&#xFD;&#xE1;&#xED;&#xE9;</test> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=34730&edit=1

« previous php.bugs (#85997) next »