- libxml_use_internal_errors: documentation ( source)
<?php
$html = "<html><meta http-equiv='content-type' content='text/html; charset=utf-8'><body><foo> <bar>bar</bar> bar</foo></body></html>";
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$foo = $xpath->query('//foo')->item(0);
$bars = $xpath->query('./bar', $foo);
echo (($bars->length == 1) ? 'PASS' : 'FAIL') . "\n";
echo ((get_class($bars->item(0)) == 'DOMElement') ? 'PASS' : 'FAIL') . "\n";