php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50278 DOM saveHTML removes space from HTML
Submitted: 2009-11-24 04:36 UTC Modified: 2015-06-10 13:29 UTC
Votes:3
Avg. Score:3.7 ± 0.5
Reproduced:0 of 0 (0.0%)
From: taylorms at mtaonline dot net Assigned: cmb (profile)
Status: Closed Package: DOM XML related
PHP Version: 5.2SVN-2009-11-24 (snap) OS: linux 2.6
Private report: No CVE-ID: None
 [2009-11-24 04:36 UTC] taylorms at mtaonline dot net
Description:
------------
Using loadHTML to load a formated HTML template file. I then use the DOM functions to create new elements before using saveHTML to dump the entire HTML to the browser.

When loading the .html file directly into the browser, the elements have correct spacing. When using loadHTML/saveHTML, spacing for a particular element is different.

I've tracked it down to the following difference. The .html looks as shown in BLK#1 below, whereas the html generated with loadHTML/saveHTML is as shown in BLK#2 below.

The newline in the .html file shown in BLK#1 produces a "space" between the elements in both FF3.5 and IE8 that is missing when the BLK#2 code is sent.

Reproduce code:
---------------
BLK#1
<form class="searchform" method="get" action="../search/search.php">
	<input id="searchbox" type="text" name="zoom_query" size="15"/>
	<input id="searchgo" type="submit" value="search"/>
</form>

BLK#2
<form action="../search/search.php" method="get" class="searchform">
<input type="text" size="15" name="zoom_query" id="searchbox"/><input type="submit" value="search" id="searchgo"/>
</form>

NOTE: In BLK#2, the two <input> tags are together on the same line, i.e., no newline between them.

Expected result:
----------------
The searchbox (textbox) and searchgo (button) are separated by a small space (about 5 px) when displaying the .html file directly (BLK#1 code). 

Actual result:
--------------
When displaying in browser using saveHTML, the space is missing, and only on this page. This is part of a template file and is identical on every page of my site. BLK#2 code produces a searchbox and searchgo button that are touching.

NOTE: I can edit the source directly in FF Firebug, add a single space or a newline to the code between the two <input> tags and the space appears as it should be.

The DOM functionality is removing newlines in other places too, but manifests itself here as a negative visual effect.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-24 08:59 UTC] taylorms at mtaonline dot net
Note: I added a <span> tag with a single space in it between the two <input> tags and it worked OK. The source became

<form action="../search/search.php" method="get" class="searchform">
<input type="text" size="15" name="zoom_query" id="searchbox"/><span> </span><input type="submit" value="search" id="searchgo"/>
</form>

The <input><span><input> are all still on one single line (3 lines total), but the space between the searchbox and searchgo elements is consistent now with all other pages. I'm baffled.
 [2009-11-24 13:35 UTC] rasmus@php.net
This looks more like a libxml2 issue than a PHP one.  Information for filing bugs against libxml2 is here:

http://xmlsoft.org/bugs.html

 [2015-06-10 13:29 UTC] cmb@php.net
-Status: Suspended +Status: Closed -Assigned To: +Assigned To: cmb
 [2015-06-10 13:29 UTC] cmb@php.net
This issue is solved by passing LIBXML_HTML_NODEFDTD as option
when loading the document. This constant is available as of PHP
5.4.0 when libxml2 >= 2.7.8 is used. See <http://3v4l.org/qs4TC>.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC