3v4l.org

run code in 300+ PHP versions simultaneously
<?php $html = <<<'HTML' <div id='makeme' class='testme'> <span id='whatspanID'>somthing</span> <p class='ptagclass'></p> </div> HTML; $dom = new DOMDocument(); $dom->loadHtml($html); $xpath = new DOMXpath($dom); $div = $xpath->evaluate('//div[@id="makeme"]')->item(0); $nodes = $xpath->evaluate('.//text()|.//@*', $div); $length = count($nodes); for($i = $length - 1; $i >= 0, --$i) { $node->parentNode->removeChild($node); } echo $dom->saveHtml($div);
Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.28
Parse error: syntax error, unexpected ')', expecting ';' in /in/1ojXM on line 17
Process exited with code 255.

preferences:
182.36 ms | 1395 KiB | 65 Q