#46737 [NEW]: SimpleXML output using asXML() should default to UTF-8

From: Date: Wed, 03 Dec 2008 11:41:07 +0000
Subject: #46737 [NEW]: SimpleXML output using asXML() should default to UTF-8
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-131555@lists.php.net to get a copy of this message
From: sites at hubmed dot org Operating system: Mac OS X PHP version: 5.2.6 PHP Bug Type: SimpleXML related Bug description: SimpleXML output using asXML() should default to UTF-8 Description: ------------ Using $xml->asXML() to output an XML document as a string from SimpleXML seems to be defaulting to ISO 8859-1 rather than UTF-8, despite all other operations being in UTF-8 (and with LANG and LC_ALL being set to UTF-8). There is a workaround, by manually setting '<?xml version="1.0" encoding="UTF-8"?>' at the start of any imported XML, but it seems strange that there isn't anywhere to set this default permanently. The behaviour of asXML() also seems to vary when printing part of a SimpleXML object (where it uses UTF-8) rather than the whole document (where it uses ISO 8859-1). Adding putenv('LANG=en_GB.UTF-8'); setlocale(LC_ALL, 'en_GB.UTF-8'); to the script doesn't seem to help. Reproduce code: --------------- // manually set encoding to UTF-8 $doc = simplexml_load_string('<?xml version="1.0" encoding="UTF-8"?><text>umlaut ü here</text>'); print $doc->asXML() . "\n"; // defaults to UTF-8 $doc = simplexml_load_string('<doc><text>umlaut ü here</text></doc>'); print $doc->text->asXML() . "\n\n"; // defaults to ISO 8859-1 $doc = simplexml_load_string('<text>umlaut ü here</text>'); print $doc->asXML() . "\n"; Expected result: ---------------- <?xml version="1.0" encoding="UTF-8"?> <text>umlaut ü here</text> <text>umlaut ü here</text> <?xml version="1.0"?> <text>umlaut ü here</text> Actual result: -------------- <?xml version="1.0" encoding="UTF-8"?> <text>umlaut ü here</text> <text>umlaut ü here</text> <?xml version="1.0"?> <text>umlaut &#xFC; here</text> -- Edit bug report at http://bugs.php.net/?id=46737&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46737&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46737&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46737&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46737&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=46737&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=46737&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46737&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46737&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46737&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46737&r=support Expected behavior: http://bugs.php.net/fix.php?id=46737&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46737&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46737&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46737&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46737&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46737&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46737&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46737&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46737&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46737&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46737&r=mysqlcfg

« previous php.bugs (#131555) next »