3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $dom=new DOMDocument(); $dom->loadXML(<<<XML <?xml version="1.0"?> <alerts> <alert> <id>3</id> <msg_type>1</msg_type> <msg>Some Message</msg> <url>Some Link</url> <status>0</status> <create_date>1388049941</create_date> <update_date>1388052529</update_date> </alert> <alert> <id>6</id> <msg_type>1</msg_type> <msg>Some Message</msg> <url>Some Link</url> <status>0</status> <create_date>1388049941</create_date> <update_date>1388052529</update_date> </alert> <alert> <id>14</id> <msg_type>1</msg_type> <msg>Some Message</msg> <url>Some Link</url> <status>0</status> <create_date>1388049941</create_date> <update_date>1388052529</update_date> </alert> <alert> <id>24</id> <msg_type>1</msg_type> <msg>Some Message</msg> <url>Some Link</url> <status>0</status> <create_date>1388049941</create_date> <update_date>1388052529</update_date> </alert> </alerts> XML ); $target=new DOMDocument(); $target->loadXML(<<<XML <?xml version="1.0"?> <alerts> </alerts> XML ); $xpath=new DOMXPath($dom); $nodeList=$xpath->query('alert[msg_type=1]'); $myID=14; foreach($nodeList as $node) { foreach($node->childNodes as $child) { if($child->nodeName=="id") { if($child->textContent==$myID) { $target->documentElement->appendChild($target->importNode($node,true)); $node->parentNode->removeChild($node); } break; } } } echo $dom->saveXML(); echo "\n"; echo $target->saveXML();
Output for 5.0.0 - 7.1.0
<?xml version="1.0"?> <alerts> <alert> <id>3</id> <msg_type>1</msg_type> <msg>Some Message</msg> <url>Some Link</url> <status>0</status> <create_date>1388049941</create_date> <update_date>1388052529</update_date> </alert> <alert> <id>6</id> <msg_type>1</msg_type> <msg>Some Message</msg> <url>Some Link</url> <status>0</status> <create_date>1388049941</create_date> <update_date>1388052529</update_date> </alert> <alert> <id>24</id> <msg_type>1</msg_type> <msg>Some Message</msg> <url>Some Link</url> <status>0</status> <create_date>1388049941</create_date> <update_date>1388052529</update_date> </alert> </alerts> <?xml version="1.0"?> <alerts> <alert> <id>14</id> <msg_type>1</msg_type> <msg>Some Message</msg> <url>Some Link</url> <status>0</status> <create_date>1388049941</create_date> <update_date>1388052529</update_date> </alert></alerts>
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: domdocument in /in/avFJI on line 2
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: domdocument in /in/avFJI on line 2