Bug #67727 [NEW]: Inconsistent loading and saving of DOMDocument

From: Date: Thu, 31 Jul 2014 14:35:02 +0000
Subject: Bug #67727 [NEW]: Inconsistent loading and saving of DOMDocument
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186912@lists.php.net to get a copy of this message
From: villascape at gmail dot com Operating system: Centos 6.5 PHP version: 5.5.15 Package: DOM XML related Bug Type: Bug Bug description:Inconsistent loading and saving of DOMDocument Description: ------------ DOMDocument::loadHTML() and DOMDocument::saveHTML() is not consistent for some input strings; specifically '<body>&nbsp;</body>'. Note that I am using PHP version 5.5.14-1.ius.centos6.x86_64, and not 5.5.15. Test script: --------------- <?php $str1='<body>&nbsp;</body>'; echo('Initial<pre>'.htmlspecialchars($str1).'</pre>'); //<body>&nbsp;</body> $dom = new DOMDocument(); //Default is UTF-8, but iso-8859-1 is available if required $dom->loadHTML($str1); $xpath = new DOMXPath($dom); $body = $dom->getElementsByTagName('body')->item(0); $str2=$dom->saveHTML($body); echo('First Option 1<pre>'.htmlspecialchars($str2).'</pre>'); //<body> </body> $dom->loadHTML($str2); $xpath = new DOMXPath($dom); $body = $dom->getElementsByTagName('body')->item(0); $str3=$dom->saveHTML($body); echo('Second Option 1<pre>'.htmlspecialchars($str3).'</pre>'); //<body>Â </body> ?> Expected result: ---------------- Initial String <body>&nbsp;</body> Returned String Pass 1 <body>&nbsp;</body> Returned String Pass 2 <body>&nbsp;</body> Actual result: -------------- Initial String <body>&nbsp;</body> Returned String Pass 1 <body> </body> Returned String Pass 2 <body>Â </body> -- Edit bug report at https://bugs.php.net/bug.php?id=67727&edit=1 --

« previous php.bugs (#186912) next »