3v4l.org

run code in 300+ PHP versions simultaneously
<?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";

preferences:
36.3 ms | 402 KiB | 5 Q