|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #74628 DOM auto remove HTML closing tag in <script> tag when save
Submitted: 2017-05-22 04:27 UTC Modified: 2017-05-22 16:37 UTC
Avg. Score:4.4 ± 0.9
Reproduced:7 of 7 (100.0%)
Same Version:4 (57.1%)
Same OS:1 (14.3%)
From: tidus2102 at gmail dot com Assigned:
Status: Suspended Package: DOM XML related
PHP Version: 7.1.5 OS: OSX El Capitan
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: tidus2102 at gmail dot com
New email:
PHP Version: OS:


 [2017-05-22 04:27 UTC] tidus2102 at gmail dot com

DOM auto remove HTML closing tag in <script> tag when save. Please check test script below.

Test script:
$html = <<<HTML
        $dom = new DOMDocument();
        $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', "UTF-8"), LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED);

        echo $dom->saveHTML();

Expected result:
All content in <script> tag need to be exactly the same as original HTML code.


Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-05-22 16:37 UTC]
-Status: Open +Status: Suspended
 [2017-05-22 16:37 UTC]
Unfortunately, libxml isn't really HTML5 compatible yet, and there
isn't much we can do about that. You have to stick to conforming
HTML 4.01, and write <\/h1>, see <>.
 [2021-03-04 11:34 UTC] gijovarghese141 at gmail dot com
Adding LIBXML_SCHEMA_CREATE to loadHTML() as an option will fix the issue

$dom->loadHTML($html, LIBXML_SCHEMA_CREATE);
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Feb 25 09:01:26 2024 UTC