php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52012 DOMDocument throws Unexpected end tag error when loading valid HTML
Submitted: 2010-06-06 23:01 UTC Modified: 2010-06-07 13:42 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: xwisdom at gmail dot com Assigned:
Status: Not a bug Package: DOM XML related
PHP Version: 5.3.2 OS: Windows XP
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
39 + 39 = ?
Subscribe to this entry?

 
 [2010-06-06 23:01 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-07 13:42 UTC] rrichards@php.net
-Status: Open +Status: Bogus
 [2010-06-07 13:42 UTC] rrichards@php.net
Behavior is due to libxml2 handling of HTML not PHP
 [2012-07-12 10:26 UTC] oridan82 at gmail dot com
Dos anybody know of any workarounds for this issue?
 [2015-01-30 04:25 UTC] kmb dot foo at gmail dot com
Has anyone figured out a workaround?  This (https://bugs.php.net/bug.php?id=49366) bug admitted the issue of not being able to create unescaped slashes JSON.  So now I (and the rest of the world) can create something I cannot easily parse.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat Sep 18 06:03:37 2021 UTC