- libxml_use_internal_errors: documentation ( source)
<?php
$html = "<html><body><div> <p>foo</p> foo</div></body></html>";
$doc = new DOMDocument();
libxml_use_internal_errors(true);
$doc->loadHTML($html);
$xpath = new DOMXPath($doc);
$div = $xpath->query('//div')->item(0);
$ps = $xpath->query('./p', $div);
echo (($ps->length == 1) ? 'PASS' : 'FAIL') . "\n";
echo ((get_class($ps->item(0)) == 'DOMElement') ? 'PASS' : 'FAIL') . "\n";