3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $string = <<<XML <sizes> <size label="Square" width="75" height="75" /> <size label="Thumbnail" width="100" height="62" /> <size label="Small" width="112" height="69">small</size> <size label="Large" width="112" height="69">large</size> </sizes> XML; $xml = simplexml_load_string($string); $result = $xml->xpath("//size"); // print the first (and only) member of the array var_dump($result);
based on o0lN1
Output for 5.3.19 - 5.3.29, 5.5.27 - 5.5.35, 5.6.11 - 7.2.0
array(4) { [0]=> object(SimpleXMLElement)#2 (1) { ["@attributes"]=> array(3) { ["label"]=> string(6) "Square" ["width"]=> string(2) "75" ["height"]=> string(2) "75" } } [1]=> object(SimpleXMLElement)#3 (1) { ["@attributes"]=> array(3) { ["label"]=> string(9) "Thumbnail" ["width"]=> string(3) "100" ["height"]=> string(2) "62" } } [2]=> object(SimpleXMLElement)#4 (2) { ["@attributes"]=> array(3) { ["label"]=> string(5) "Small" ["width"]=> string(3) "112" ["height"]=> string(2) "69" } [0]=> string(5) "small" } [3]=> object(SimpleXMLElement)#5 (2) { ["@attributes"]=> array(3) { ["label"]=> string(5) "Large" ["width"]=> string(3) "112" ["height"]=> string(2) "69" } [0]=> string(5) "large" } }
Output for 5.4.9 - 5.5.26, 5.6.8 - 5.6.10
array(4) { [0]=> object(SimpleXMLElement)#2 (1) { ["@attributes"]=> array(3) { ["label"]=> string(6) "Square" ["width"]=> string(2) "75" ["height"]=> string(2) "75" } } [1]=> object(SimpleXMLElement)#3 (1) { ["@attributes"]=> array(3) { ["label"]=> string(9) "Thumbnail" ["width"]=> string(3) "100" ["height"]=> string(2) "62" } } [2]=> object(SimpleXMLElement)#4 (1) { ["@attributes"]=> array(3) { ["label"]=> string(5) "Small" ["width"]=> string(3) "112" ["height"]=> string(2) "69" } } [3]=> object(SimpleXMLElement)#5 (1) { ["@attributes"]=> array(3) { ["label"]=> string(5) "Large" ["width"]=> string(3) "112" ["height"]=> string(2) "69" } } }