3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $xml = '<lib id="ITEM_I_WANT_TO_DOWNLOAD_1" revision="0000"> <part id="0000" type="ch"/> <part id="0000" type="ls"/> <part id="0000" type="rs"/> <part id="0000" type="ch"/> </lib> <lib id="ITEM_I_WANT_TO_DOWNLOAD_2" revision="0000"> <part id="0000" type="ch"/> <part id="0000" type="ls"/> <part id="0000" type="rs"/> <part id="0000" type="ch"/> </lib>'; $xml = '<mydocument>' . $xml . '</mydocument>'; // repair invalid xml https://stackoverflow.com/q/4544272/2943403 $doc = new DOMDocument(); $doc->loadXml($xml); $xpath = new DOMXpath($doc); foreach ($xpath->evaluate('//lib/@id') as $attr) { $result[] = $attr->value; } var_export($result);
based on NEA7p
Output for 5.6.38 - 7.3.0rc3
array ( 0 => 'ITEM_I_WANT_TO_DOWNLOAD_1', 1 => 'ITEM_I_WANT_TO_DOWNLOAD_2', )