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('.//@*', $div); $length = count($nodes); for($i = $length - 1; $i >= 0; --$i) { $node = $nodes->item($i); var_dump($node); $node->parentNode->removeChild($node); } echo $dom->saveHtml($div);
Output for git.master, git.master_jit, rfc.property-hooks
object(DOMAttr)#7 (21) { ["specified"]=> bool(true) ["schemaTypeInfo"]=> NULL ["name"]=> string(5) "class" ["value"]=> string(9) "ptagclass" ["ownerElement"]=> string(22) "(object value omitted)" ["nodeName"]=> string(5) "class" ["nodeValue"]=> string(9) "ptagclass" ["nodeType"]=> int(2) ["parentNode"]=> string(22) "(object value omitted)" ["childNodes"]=> string(22) "(object value omitted)" ["firstChild"]=> string(22) "(object value omitted)" ["lastChild"]=> string(22) "(object value omitted)" ["previousSibling"]=> NULL ["nextSibling"]=> NULL ["attributes"]=> NULL ["ownerDocument"]=> string(22) "(object value omitted)" ["namespaceURI"]=> NULL ["prefix"]=> string(0) "" ["localName"]=> string(5) "class" ["baseURI"]=> NULL ["textContent"]=> string(9) "ptagclass" } Fatal error: Uncaught DOMException: Not Found Error in /in/mYH4Y:20 Stack trace: #0 /in/mYH4Y(20): DOMNode->removeChild(Object(DOMAttr)) #1 {main} thrown in /in/mYH4Y on line 20
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.94 ms | 402 KiB | 8 Q