Edit report at http://bugs.php.net/bug.php?id=48509&edit=1
ID: 48509 Updated by: rricha...@php.net Reported by: k...@php.net Summary: formatOutput does not work with saveHTML -Status: Assigned +Status: Duplicate Type: Bug Package: DOM XML related Operating System: Mac OS X 10.5.7 PHP Version: 5.3CVS-2009-06-09 (CVS) Assigned To: rrichards New Comment: marking this as duplicate of bug #35673 which has now been merged into the the 5_3 tree. Note that your example will not work because HTML output is only formatted when in the context of an HTML document (must have been loaded via loadHTML/File) - due to the limited HTML support in DOM extension. Previous Comments: ------------------------------------------------------------------------ [2010-03-06 23:23:19] fel...@php.net I got '<html><head><title>This is the title</title></head></html>' on 5_2, 5_3 and HEAD using saveHTML(), and using saveHTMLfile() I got: <html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>This is the title</title> </head></html> ------------------------------------------------------------------------ [2009-06-11 08:36:09] chr...@php.net Rob: I applied the patch to 5_3, but it doesn't format with libxml 2.7.3, do you know something, what's wrong here? Although, I didn't test with 2.6.23. ------------------------------------------------------------------------ [2009-06-10 06:49:31] chr...@php.net RIght, that never was backported to the 5_3 branch. But we're currently in a commit freeze, so I can't check it in, but will as soon as I am allowed to do it. That's the patch by the way: http://cvs.php.net/viewvc.cgi/php-src/ext/dom/document.c? r1=1.78&r2=1.79&pathrev=MAIN&view=patch ------------------------------------------------------------------------ [2009-06-09 16:51:53] k...@php.net Description: ------------ While writing test cases on Oslo TestFest 2009 I just found that the $dom->formatOutput does not work with $dom->saveHTML() (even though it seems to have been resolved here: http://bugs.php.net/bug.php?id=35673) xmllint says: $ xmllint --format --html output.html <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>This is the title</title> </head></html> so according to Hannes here this seems to be a bug in PHP 5.3 (may be that it's fixed i HEAD but not backported?). Reproduce code: --------------- <?php $doc = new DOMDocument('1.0'); $doc->formatOutput = true; $root = $doc->createElement('html'); $root = $doc->appendChild($root); $head = $doc->createElement('head'); $head = $root->appendChild($head); $title = $doc->createElement('title'); $title = $head->appendChild($title); $text = $doc->createTextNode('This is the title'); $text = $title->appendChild($text); echo $doc->saveHTML(); ?> Expected result: ---------------- <html> <head> <title>This is the title</title> </head> </html> Actual result: -------------- <html><head><title>This is the title</title></head></html> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=48509&edit=1