3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<EOT <html><body><h2>Hello</h2> <h2>World</h2><h2><strong>!</strong></h2></body></html> EOT; $dom = new DOMDocument(); $dom->loadHTML($html); foreach($dom->getElementsByTagName('h2') as $h2) { if(!count($h2->getElementsByTagName('*'))){ var_dump($h2->textContent); } }

preferences:
36.62 ms | 404 KiB | 5 Q