3v4l.org

run code in 300+ PHP versions simultaneously
<?php $root = new DOMDocument(); $root->formatOutput = true; $root->loadXML('<article id=""></article>'); for($i=0;$i<=300;$i++){ $node = new DOMDocument(); $node->loadXML('<section id="'.$i.'" data-country="DEU"><h1>Überschrift</h1><h2>Überschrift2</h2><p>Content</p></section>'); $xpath = new DOMXPath($node); $query = '//section'; $entries=$xpath->query($query); $entries->removeAttribute('data-country'); $entries->setAttribute("data-country", substr(md5(rand()),0,7)); $query = '//h1'; $entries=$xpath->query($query); if($entries->length===1){ $entries->item(0)->nodeValue = ""; $entries->item(0)->appendChild($node->createTextNode("Text ".$i)); } $query = '//h2'; $entries=$xpath->query($query); if($entries->length===1){ $entries->item(0)->nodeValue = ""; $entries->item(0)->appendChild($node->createTextNode(md5("Text ".$i))); } $node = $root->importNode($node->documentElement, true); $root->documentElement->appendChild($node); } print $root->saveXML();
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.25, 7.2.0 - 7.2.13, 7.3.0 - 7.3.1
Fatal error: Uncaught Error: Call to undefined method DOMNodeList::removeAttribute() in /in/JdsF1:15 Stack trace: #0 {main} thrown in /in/JdsF1 on line 15
Process exited with code 255.

preferences:
70.22 ms | 402 KiB | 52 Q