Last active
September 23, 2016 03:33
-
-
Save stemar/2c793cb8da632f834fc756a7146c946a to your computer and use it in GitHub Desktop.
DOMDocument::loadHTML() removing invalid tags without adding DOCTYPE and <html> tag
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Invalid end tag </s> | |
| $html = <<<HTML | |
| <table> | |
| <tr> | |
| <td>123</s></td> | |
| <td>456</td> | |
| </tr> | |
| </table> | |
| HTML; | |
| $doc = new DOMDocument(); | |
| libxml_use_internal_errors(true); | |
| $doc->loadHTML($html, LIBXML_HTML_NODEFDTD | LIBXML_HTML_NOIMPLIED); | |
| libxml_clear_errors(); | |
| echo $doc->saveHTML(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Result: the
</s>invalid end tag is removed.