php.net |  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
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: knut@php.net 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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: knut@php.net
New email:
PHP Version: OS:

 

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

Patches

Pull Requests

History

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



 [2010-03-06 23:23 UTC] felipe@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>
 [2010-04-02 18:23 UTC] rrichards@php.net
-Status: Assigned +Status: Duplicate
 [2010-04-02 18:23 UTC] rrichards@php.net
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-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 02 12:01:29 2025 UTC