|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-05-22 11:41 UTC] douglas dot wright at pre-school dot org dot uk
Description:
------------
There is a regression in PHP5.5RC where empty text nodes seem to be lost e.g. <script src=""></script> is turned into <script src=""/>
This breaks XHTML pages because browsers don't recognise the self-closing syntax.
In PHP 5.3 and 5.4 the two calls below had different output
$doc->createElement('script') output <script/>
$doc->createElement('script', '') output <script></script>
In PHP5.5, they both output <script/> only. Documents parsed using loadXML suffer this too - <script></script> loses the inner text node and is transformed into <script/>.
Test script:
---------------
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
$doc = new DOMDocument;
$script = $doc->createElement('script', '');
$script->setAttribute('src', 'foo.js');
$doc->appendChild($script);
echo $doc->saveXML();
$doc->loadXML('<script src="abc.js"></script>');
echo $doc->saveXML();
Expected result:
----------------
<?xml version="1.0"?>
<script src="foo.js"></script>
<?xml version="1.0"?>
<script src="foo.js"></script>
Actual result:
--------------
<?xml version="1.0"?>
<script src="foo.js"/>
<?xml version="1.0"?>
<script src="foo.js"/>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 10:00:01 2025 UTC |
Hi The workaround of inserting an empty text node manually after element creation still seems to work, but inserting a text node is what the $value param in createElement($name,$value) is surely for? i.e. $script = $doc->createElement ('script', '') //not working in 5.5 is the same thing as: $script = $doc->createElement ('script'); $script->appendChild ($doc->createTextNode ('')); //does work in 5.5 On setting, this creates a Text node with the unparsed contents of the string