Skip to content Skip to sidebar Skip to footer

Find What Part Of Html Is Invalid With PHP

I tried several methods to find out what part of a html string is invalid $dom->loadHTML($badHtml); $tidy->cleanRepair(); simplexml_load_string($badHtml); None is clear rega

Solution 1:

I'd try loading the offending HTML into a DOM Document (as you are already doing) and then using simplexml to fix things. You should be able to run a quick diff to see where the errors are.

error_reporting(0);

$badHTML = '<p>Some <em><strong>badly</em> nested</stong> tags</p>';

$doc = new DOMDocument();
$doc->encoding = 'UTF-8';

$doc->loadHTML($badHTML);

$goodHTML = simplexml_import_dom($doc)->asXML();

Solution 2:

You can compare cleaned and bad version with PHP Inline-Diff found in answer to that stackoverflow question.


Post a Comment for "Find What Part Of Html Is Invalid With PHP"