|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48509 formatOutput does not work with saveHTML
Submitted: 2009-06-09 16:51 UTC Modified: 2010-04-02 18:23 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: Assigned: rrichards (profile)
Status: Duplicate Package: DOM XML related
PHP Version: 5.3CVS-2009-06-09 (CVS) OS: Mac OS X 10.5.7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
New email:
PHP Version: OS:


 [2009-06-09 16:51 UTC]
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:

xmllint says:

$ xmllint --format --html output.html 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is the title</title>

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:
$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:
    <title>This is the title</title>

Actual result:
<html><head><title>This is the title</title></head></html>


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-06-10 06:49 UTC]
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:
 [2009-06-11 08:36 UTC]
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.

 [2010-03-06 23:23 UTC]
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:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is the title</title>
 [2010-04-02 18:23 UTC]
-Status: Assigned +Status: Duplicate
 [2010-04-02 18:23 UTC]
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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sun Oct 01 23:01:24 2023 UTC