3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xml_str = '<?xml version="1.0" encoding="UTF-8" standalone="no"?> <ExpResponse engineVersion="201404_02a" status="OK" xml:space="preserve"> <MethodReturn> <TrainInformation displayName="普通" driveComment="平日運転" guideComment="" traffic="1" type="Train"> <StopStationList> <StopStation areaCode="16" code="29181" departureTime="1810" getOff="False" getOn="False" kenCode="26" name="国際会館"/> <StopStation areaCode="16" arraivalTime="1812" arrivalTime="1812" code="29182" departureTime="1812" getOff="False" getOn="False" kenCode="26" name="松ケ崎(京都府)"/> <StopStation areaCode="16" arraivalTime="1814" arrivalTime="1814" code="25641" departureTime="1814" getOff="False" getOn="False" kenCode="26" name="北山(京都府)"/> <StopStation areaCode="16" arraivalTime="1816" arrivalTime="1816" code="25639" departureTime="1816" getOff="False" getOn="False" kenCode="26" name="北大路"/> <StopStation areaCode="16" arraivalTime="1818" arrivalTime="1818" code="25656" departureTime="1818" getOff="False" getOn="False" kenCode="26" name="鞍馬口"/> <StopStation areaCode="16" arraivalTime="1819" arrivalTime="1819" code="25598" departureTime="1820" getOff="False" getOn="False" kenCode="26" name="今出川"/> <StopStation areaCode="16" arraivalTime="1822" arrivalTime="1822" code="25767" departureTime="1822" getOff="False" getOn="False" kenCode="26" name="丸太町(京都市営)"/> <StopStation areaCode="16" arraivalTime="1824" arrivalTime="1824" code="25607" departureTime="1824" getOff="False" getOn="False" kenCode="26" name="烏丸御池"/> <StopStation areaCode="16" arraivalTime="1825" arrivalTime="1825" code="25681" departureTime="1826" getOff="False" getOn="False" kenCode="26" name="四条(京都市営)"/> <StopStation areaCode="16" arraivalTime="1827" arrivalTime="1827" code="25670" departureTime="1828" getOff="False" getOn="False" kenCode="26" name="五条(京都市営)"/> <StopStation areaCode="16" arraivalTime="1829" arrivalTime="1829" code="25647" departureTime="1830" getOff="False" getOn="False" kenCode="26" name="京都"/> <StopStation areaCode="16" arraivalTime="1831" arrivalTime="1831" code="25651" departureTime="1831" getOff="False" getOn="False" kenCode="26" name="九条(京都府)"/> <StopStation areaCode="16" arraivalTime="1832" arrivalTime="1832" code="25694" departureTime="1833" getOff="False" getOn="False" kenCode="26" name="十条(京都市営)"/> <StopStation areaCode="16" arraivalTime="1834" arrivalTime="1834" code="25650" departureTime="1835" getOff="False" getOn="False" kenCode="26" name="くいな橋"/> <StopStation areaCode="16" arraivalTime="1836" arrivalTime="1836" code="25701" departureTime="1838" getOff="False" getOn="False" kenCode="26" name="竹田(京都府)"/> <StopStation areaCode="16" arraivalTime="1840" arrivalTime="1840" code="25752" departureTime="1840" getOff="False" getOn="False" kenCode="26" name="伏見(京都府)"/> <StopStation areaCode="16" arraivalTime="1842" arrivalTime="1842" code="25648" departureTime="1842" getOff="False" getOn="False" kenCode="26" name="近鉄丹波橋"/> <StopStation areaCode="16" arraivalTime="1843" arrivalTime="1843" code="25780" departureTime="1844" getOff="False" getOn="False" kenCode="26" name="桃山御陵前"/> <StopStation areaCode="16" arraivalTime="1847" arrivalTime="1847" code="25776" departureTime="1847" getOff="False" getOn="False" kenCode="26" name="向島"/> <StopStation areaCode="16" arraivalTime="1850" arrivalTime="1850" code="25618" departureTime="1851" getOff="False" getOn="False" kenCode="26" name="小倉(京都府)"/> <StopStation areaCode="16" arraivalTime="1852" arrivalTime="1852" code="25594" departureTime="1852" getOff="False" getOn="False" kenCode="26" name="伊勢田"/> <StopStation areaCode="16" arraivalTime="1854" arrivalTime="1854" code="25614" departureTime="1859" getOff="False" getOn="False" kenCode="26" name="大久保(京都府)"/> <StopStation areaCode="16" arraivalTime="1900" arrivalTime="1900" code="25653" departureTime="1901" getOff="False" getOn="False" kenCode="26" name="久津川"/> <StopStation areaCode="16" arraivalTime="1902" arrivalTime="1902" code="25716" departureTime="1902" getOff="False" getOn="False" kenCode="26" name="寺田(京都府)"/> <StopStation areaCode="16" arraivalTime="1904" arrivalTime="1904" code="25722" departureTime="1904" getOff="False" getOn="False" kenCode="26" name="富野荘"/> <StopStation areaCode="16" arraivalTime="1907" arrivalTime="1907" code="25690" getOff="False" getOn="False" kenCode="26" name="新田辺"/> </StopStationList> </TrainInformation> </MethodReturn> </ExpResponse>'; $xml = simplexml_load_string($xml_str); $result = xml_to_array($xml); print_r($result); function xml_to_array($xml) { $attributes = array(); $namespaces = $xml->getNameSpaces(true); if (count($namespaces) > 0) { foreach ($namespaces as $ns_key => $ns_val) { foreach ($xml->attributes($ns_val) as $key => $val) { $attributes[$ns_key.":".$key] = (string)$val; } } } foreach ($xml->attributes() as $key => $val) { $attributes[$key] = (string)$val; } $is_single = (count($xml->children()) === 1); foreach ($xml->children() as $key => $val) { $res = xml_to_array($val); if ($is_single) { $attributes[$key] = $res; } elseif (array_key_exists($key, $attributes)) { array_push($attributes[$key], $res); } else { $attributes[$key] = array($res); } } return $attributes; }
Output for 5.1.2 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [xml:space] => preserve [engineVersion] => 201404_02a [status] => OK [MethodReturn] => Array ( [TrainInformation] => Array ( [displayName] => 普通 [driveComment] => 平日運転 [guideComment] => [traffic] => 1 [type] => Train [StopStationList] => Array ( [StopStation] => Array ( [0] => Array ( [areaCode] => 16 [code] => 29181 [departureTime] => 1810 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 国際会館 ) [1] => Array ( [areaCode] => 16 [arraivalTime] => 1812 [arrivalTime] => 1812 [code] => 29182 [departureTime] => 1812 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 松ケ崎(京都府) ) [2] => Array ( [areaCode] => 16 [arraivalTime] => 1814 [arrivalTime] => 1814 [code] => 25641 [departureTime] => 1814 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 北山(京都府) ) [3] => Array ( [areaCode] => 16 [arraivalTime] => 1816 [arrivalTime] => 1816 [code] => 25639 [departureTime] => 1816 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 北大路 ) [4] => Array ( [areaCode] => 16 [arraivalTime] => 1818 [arrivalTime] => 1818 [code] => 25656 [departureTime] => 1818 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 鞍馬口 ) [5] => Array ( [areaCode] => 16 [arraivalTime] => 1819 [arrivalTime] => 1819 [code] => 25598 [departureTime] => 1820 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 今出川 ) [6] => Array ( [areaCode] => 16 [arraivalTime] => 1822 [arrivalTime] => 1822 [code] => 25767 [departureTime] => 1822 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 丸太町(京都市営) ) [7] => Array ( [areaCode] => 16 [arraivalTime] => 1824 [arrivalTime] => 1824 [code] => 25607 [departureTime] => 1824 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 烏丸御池 ) [8] => Array ( [areaCode] => 16 [arraivalTime] => 1825 [arrivalTime] => 1825 [code] => 25681 [departureTime] => 1826 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 四条(京都市営) ) [9] => Array ( [areaCode] => 16 [arraivalTime] => 1827 [arrivalTime] => 1827 [code] => 25670 [departureTime] => 1828 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 五条(京都市営) ) [10] => Array ( [areaCode] => 16 [arraivalTime] => 1829 [arrivalTime] => 1829 [code] => 25647 [departureTime] => 1830 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 京都 ) [11] => Array ( [areaCode] => 16 [arraivalTime] => 1831 [arrivalTime] => 1831 [code] => 25651 [departureTime] => 1831 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 九条(京都府) ) [12] => Array ( [areaCode] => 16 [arraivalTime] => 1832 [arrivalTime] => 1832 [code] => 25694 [departureTime] => 1833 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 十条(京都市営) ) [13] => Array ( [areaCode] => 16 [arraivalTime] => 1834 [arrivalTime] => 1834 [code] => 25650 [departureTime] => 1835 [getOff] => False [getOn] => False [kenCode] => 26 [name] => くいな橋 ) [14] => Array ( [areaCode] => 16 [arraivalTime] => 1836 [arrivalTime] => 1836 [code] => 25701 [departureTime] => 1838 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 竹田(京都府) ) [15] => Array ( [areaCode] => 16 [arraivalTime] => 1840 [arrivalTime] => 1840 [code] => 25752 [departureTime] => 1840 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 伏見(京都府) ) [16] => Array ( [areaCode] => 16 [arraivalTime] => 1842 [arrivalTime] => 1842 [code] => 25648 [departureTime] => 1842 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 近鉄丹波橋 ) [17] => Array ( [areaCode] => 16 [arraivalTime] => 1843 [arrivalTime] => 1843 [code] => 25780 [departureTime] => 1844 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 桃山御陵前 ) [18] => Array ( [areaCode] => 16 [arraivalTime] => 1847 [arrivalTime] => 1847 [code] => 25776 [departureTime] => 1847 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 向島 ) [19] => Array ( [areaCode] => 16 [arraivalTime] => 1850 [arrivalTime] => 1850 [code] => 25618 [departureTime] => 1851 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 小倉(京都府) ) [20] => Array ( [areaCode] => 16 [arraivalTime] => 1852 [arrivalTime] => 1852 [code] => 25594 [departureTime] => 1852 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 伊勢田 ) [21] => Array ( [areaCode] => 16 [arraivalTime] => 1854 [arrivalTime] => 1854 [code] => 25614 [departureTime] => 1859 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 大久保(京都府) ) [22] => Array ( [areaCode] => 16 [arraivalTime] => 1900 [arrivalTime] => 1900 [code] => 25653 [departureTime] => 1901 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 久津川 ) [23] => Array ( [areaCode] => 16 [arraivalTime] => 1902 [arrivalTime] => 1902 [code] => 25716 [departureTime] => 1902 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 寺田(京都府) ) [24] => Array ( [areaCode] => 16 [arraivalTime] => 1904 [arrivalTime] => 1904 [code] => 25722 [departureTime] => 1904 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 富野荘 ) [25] => Array ( [areaCode] => 16 [arraivalTime] => 1907 [arrivalTime] => 1907 [code] => 25690 [getOff] => False [getOn] => False [kenCode] => 26 [name] => 新田辺 ) ) ) ) ) )
Output for 5.0.0 - 5.1.1
Fatal error: Call to undefined method SimpleXMLElement::getNameSpaces() in /in/iTbSd on line 49
Process exited with code 255.
Output for 4.4.5 - 4.4.9
Fatal error: Call to undefined function: simplexml_load_string() in /in/iTbSd on line 40
Process exited with code 255.
Output for 4.3.2 - 4.4.4
Fatal error: Call to undefined function: simplexml_load_string() in /in/iTbSd on line 40
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Call to undefined function: simplexml_load_string() in /in/iTbSd on line 40