3v4l.org

run code in 500+ 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:
95.83 ms | 1252 KiB | 5 Q