3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $string = <<<XML <a> <b> <c>text</c> <c>stuff</c> </b> <d> <c>code</c> </d> </a> XML; // load source XML and create Xpath instance $source = new DOMDocument(); $source->loadxml($string); $xpath = new DOMXpath($source); // create target document with document element $target = new DOMDocument(); $root = $target->appendChild($dom->createElement('d')); // copy nodes from source to target foreach ($xpath->evaluate('/a/b/c') as $child) { $root->appendChild($target->importNode($child)); } // output target echo $target->saveXml();
Output for 5.4.0 - 5.4.29
Parse error: syntax error, unexpected end of file in /in/hlL1B on line 30
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected $end in /in/hlL1B on line 30
Process exited with code 255.