Bug #52012 [Com]: DOMDocument throws Unexpected end tag error when loading valid HTML
| From: | oridan82 at gmail dot com | Date: | Thu, 12 Jul 2012 10:26:45 +0000 |
| Subject: | Bug #52012 [Com]: DOMDocument throws Unexpected end tag error when loading valid HTML | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-171897@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52012&edit=1
ID: 52012
Comment by: oridan82 at gmail dot com
Reported by: xwisdom at gmail dot com
Summary: DOMDocument throws Unexpected end tag error when
loading valid HTML
Status: Not a bug
Type: Bug
Package: DOM XML related
Operating System: Windows XP
PHP Version: 5.3.2
Block user comment: N
Private report: N
New Comment:
Dos anybody know of any workarounds for this issue?
Previous Comments:
------------------------------------------------------------------------
[2010-06-07 13:42:16] rrichards@php.net
Behavior is due to libxml2 handling of HTML not PHP
------------------------------------------------------------------------
[2010-06-06 23:01:07] xwisdom at gmail dot com
Description:
------------
I'm getting a php warning from DOMDocument after running a test script in an
attempt to load some html inside the DOM and then echo the html to the
browser:
Warning: DOMDocument::loadHTML() [domdocument.loadhtml]: Unexpected end tag
: strong in Entity, line: 8 in C:\www\dom-test.php on line 23
The problem is that DOMDocument::loadHTML() attempts to remove the
'</strong>' tag from within a JavaScript string variable inside the
<script> tag. If I try to wrap <!-- --> around the content of the <script>
tag it will still throw the error.
I've tested it with php 5.2.0, 5.2.6, 5.2.11, 5.3 and 5.3.2. It
appears to work just fine in version 5.2.0 but the other version throw the
above error.
See Test script
Test script:
---------------
<?php
$html = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8"/>
<script type="text/javascript">
var html = "<strong>Bold Text</strong>,Normal Text";
document.write(html);
alert(html);
</script>
</head>
<body> </body>
</html>';
$dom = new DOMDocument();
$dom->loadHTML($html);
echo $dom->saveHTML();
?>
Expected result:
----------------
Expected alert message from browser:
<strong>Bold Text</strong>,Normal Text
Actual result:
--------------
Actual alert message from browser:
<strong>Bold Text,Normal Text
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52012&edit=1