|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2015-10-30 00:44 UTC] untuned20 at gmail dot com
Description:
------------
When parsing a DOMDocument(), strings containing html are validated and probably shouldn't be.
For example when parsing a `<script>` tag containing html to be executed, the parser will validate that html. In the example script, The parser removes the `</h1>` leaving an invalid string of "<h1>hello".
Test script:
---------------
<?php
$doc = new DOMDocument();
$doc->loadXML('<html>
<head>
</head>
<body>
<script>
console.log("<h1>hello</h1>");
</script>
</body>
</html>');
echo $doc->saveHTML();
Expected result:
----------------
<html>
<head>
</head>
<body>
<script>
console.log("<h1>hello</h1>");
</script>
</body>
</html>
Actual result:
--------------
<html>
<head>
</head>r
<body>
<script>
console.log("<h1>hello");
</script>
</body>
</html>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 17 23:00:01 2025 UTC |
The above test script is wrong, it should be loadHTML() instead. Test script: --------------- <?php $doc = new DOMDocument(); $doc->loadHTML('<html> <head> </head> <body> <script> console.log("<h1>hello</h1>"); </script> </body> </html>'); echo $doc->saveHTML();