Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Сергей Шевченко
Added: Jan 16, 2018 11:54 AM
Modified: Sep 4, 2018 9:27 AM
Views: 19
  1. $htmlOk  = '<p>Good HTML fragment</p>';
  2. $htmlBad = '<p>Bad HTML fragment</p';
  3. $internalErrors = libxml_use_internal_errors(true);
  4. $doc = new DOMDocument();
  5. $doc->validateOnParse = true;
  6. $doc->loadHTML($htmlBad);
  7. echo count(libxml_get_errors()) == 0 ? 'yes' : 'no';
  8. libxml_use_internal_errors($internalErrors);