3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xml = <<<EOD <?xml version="1.0" encoding="UTF-8"?> <gesmes:Envelope xmlns:gesmes="http://www.gesmes.org/xml/2002-08-01" xmlns="http://www.ecb.int/vocabulary/2002-08-01/eurofxref"> <gesmes:subject>Reference rates</gesmes:subject> <gesmes:Sender> <gesmes:name>Eesti Pank</gesmes:name> </gesmes:Sender> <Cube> <Cube time="2014-03-04"> <Cube currency="AUD" rate="1.5392" /> <Cube currency="BGN" rate="1.9558" /> <Cube currency="BRL" rate="3.2100" /> <Cube currency="CAD" rate="1.5244" /> <Cube currency="CHF" rate="1.2172" /> <Cube currency="CNY" rate="8.4564" /> <Cube currency="CZK" rate="27.3690" /> <Cube currency="DKK" rate="7.4627" /> <Cube currency="GBP" rate="0.8246" /> <Cube currency="HKD" rate="10.6847" /> <Cube currency="HRK" rate="7.6525" /> <Cube currency="HUF" rate="311.1500" /> <Cube currency="IDR" rate="15957.1100" /> <Cube currency="ILS" rate="4.8055" /> <Cube currency="INR" rate="85.1757" /> <Cube currency="JPY" rate="140.2000" /> <Cube currency="KRW" rate="1474.4700" /> <Cube currency="LTL" rate="3.4528" /> <Cube currency="MXN" rate="18.2977" /> <Cube currency="MYR" rate="4.5049" /> <Cube currency="NOK" rate="8.2485" /> <Cube currency="NZD" rate="1.6411" /> <Cube currency="PHP" rate="61.6390" /> <Cube currency="PLN" rate="4.1865" /> <Cube currency="RON" rate="4.5183" /> <Cube currency="RUB" rate="49.7510" /> <Cube currency="SEK" rate="8.8603" /> <Cube currency="SGD" rate="1.7469" /> <Cube currency="THB" rate="44.6290" /> <Cube currency="TRY" rate="3.0520" /> <Cube currency="USD" rate="1.3768" /> <Cube currency="ZAR" rate="14.9180" /> </Cube> </Cube> </gesmes:Envelope> EOD; $sxe = new SimpleXMLElement($xml); $sxe->registerXPathNamespace('g', 'http://www.gesmes.org/xml/2002-08-01'); $sxe->registerXPathNamespace('pank', 'http://www.ecb.int/vocabulary/2002-08-01/eurofxref'); $result = $sxe->xpath('//pank:Cube'); $currencies = array(); foreach ($result as $Cube) { $attributes = $Cube->attributes(); if ( isset( $attributes['currency'], $attributes['rate'] ) ) { $currencies[ trim( $attributes['currency'] ) ] = $attributes['rate']; } } var_dump( $currencies );
Output for 5.1.2 - 5.6.28, 7.0.0 - 7.1.0
array(32) { ["AUD"]=> object(SimpleXMLElement)#36 (1) { [0]=> string(6) "1.5392" } ["BGN"]=> object(SimpleXMLElement)#37 (1) { [0]=> string(6) "1.9558" } ["BRL"]=> object(SimpleXMLElement)#38 (1) { [0]=> string(6) "3.2100" } ["CAD"]=> object(SimpleXMLElement)#39 (1) { [0]=> string(6) "1.5244" } ["CHF"]=> object(SimpleXMLElement)#40 (1) { [0]=> string(6) "1.2172" } ["CNY"]=> object(SimpleXMLElement)#41 (1) { [0]=> string(6) "8.4564" } ["CZK"]=> object(SimpleXMLElement)#42 (1) { [0]=> string(7) "27.3690" } ["DKK"]=> object(SimpleXMLElement)#43 (1) { [0]=> string(6) "7.4627" } ["GBP"]=> object(SimpleXMLElement)#44 (1) { [0]=> string(6) "0.8246" } ["HKD"]=> object(SimpleXMLElement)#45 (1) { [0]=> string(7) "10.6847" } ["HRK"]=> object(SimpleXMLElement)#46 (1) { [0]=> string(6) "7.6525" } ["HUF"]=> object(SimpleXMLElement)#47 (1) { [0]=> string(8) "311.1500" } ["IDR"]=> object(SimpleXMLElement)#48 (1) { [0]=> string(10) "15957.1100" } ["ILS"]=> object(SimpleXMLElement)#49 (1) { [0]=> string(6) "4.8055" } ["INR"]=> object(SimpleXMLElement)#50 (1) { [0]=> string(7) "85.1757" } ["JPY"]=> object(SimpleXMLElement)#51 (1) { [0]=> string(8) "140.2000" } ["KRW"]=> object(SimpleXMLElement)#52 (1) { [0]=> string(9) "1474.4700" } ["LTL"]=> object(SimpleXMLElement)#53 (1) { [0]=> string(6) "3.4528" } ["MXN"]=> object(SimpleXMLElement)#54 (1) { [0]=> string(7) "18.2977" } ["MYR"]=> object(SimpleXMLElement)#55 (1) { [0]=> string(6) "4.5049" } ["NOK"]=> object(SimpleXMLElement)#56 (1) { [0]=> string(6) "8.2485" } ["NZD"]=> object(SimpleXMLElement)#57 (1) { [0]=> string(6) "1.6411" } ["PHP"]=> object(SimpleXMLElement)#58 (1) { [0]=> string(7) "61.6390" } ["PLN"]=> object(SimpleXMLElement)#59 (1) { [0]=> string(6) "4.1865" } ["RON"]=> object(SimpleXMLElement)#60 (1) { [0]=> string(6) "4.5183" } ["RUB"]=> object(SimpleXMLElement)#61 (1) { [0]=> string(7) "49.7510" } ["SEK"]=> object(SimpleXMLElement)#62 (1) { [0]=> string(6) "8.8603" } ["SGD"]=> object(SimpleXMLElement)#63 (1) { [0]=> string(6) "1.7469" } ["THB"]=> object(SimpleXMLElement)#64 (1) { [0]=> string(7) "44.6290" } ["TRY"]=> object(SimpleXMLElement)#65 (1) { [0]=> string(6) "3.0520" } ["USD"]=> object(SimpleXMLElement)#66 (1) { [0]=> string(6) "1.3768" } ["ZAR"]=> object(SimpleXMLElement)#67 (1) { [0]=> string(7) "14.9180" } }
Output for hhvm-3.10.0 - 3.12.0
array(32) { ["AUD"]=> object(SimpleXMLElement)#41 (1) { [0]=> string(6) "1.5392" } ["BGN"]=> object(SimpleXMLElement)#44 (1) { [0]=> string(6) "1.9558" } ["BRL"]=> object(SimpleXMLElement)#47 (1) { [0]=> string(6) "3.2100" } ["CAD"]=> object(SimpleXMLElement)#50 (1) { [0]=> string(6) "1.5244" } ["CHF"]=> object(SimpleXMLElement)#53 (1) { [0]=> string(6) "1.2172" } ["CNY"]=> object(SimpleXMLElement)#56 (1) { [0]=> string(6) "8.4564" } ["CZK"]=> object(SimpleXMLElement)#59 (1) { [0]=> string(7) "27.3690" } ["DKK"]=> object(SimpleXMLElement)#62 (1) { [0]=> string(6) "7.4627" } ["GBP"]=> object(SimpleXMLElement)#65 (1) { [0]=> string(6) "0.8246" } ["HKD"]=> object(SimpleXMLElement)#68 (1) { [0]=> string(7) "10.6847" } ["HRK"]=> object(SimpleXMLElement)#71 (1) { [0]=> string(6) "7.6525" } ["HUF"]=> object(SimpleXMLElement)#74 (1) { [0]=> string(8) "311.1500" } ["IDR"]=> object(SimpleXMLElement)#77 (1) { [0]=> string(10) "15957.1100" } ["ILS"]=> object(SimpleXMLElement)#80 (1) { [0]=> string(6) "4.8055" } ["INR"]=> object(SimpleXMLElement)#83 (1) { [0]=> string(7) "85.1757" } ["JPY"]=> object(SimpleXMLElement)#86 (1) { [0]=> string(8) "140.2000" } ["KRW"]=> object(SimpleXMLElement)#89 (1) { [0]=> string(9) "1474.4700" } ["LTL"]=> object(SimpleXMLElement)#92 (1) { [0]=> string(6) "3.4528" } ["MXN"]=> object(SimpleXMLElement)#95 (1) { [0]=> string(7) "18.2977" } ["MYR"]=> object(SimpleXMLElement)#98 (1) { [0]=> string(6) "4.5049" } ["NOK"]=> object(SimpleXMLElement)#101 (1) { [0]=> string(6) "8.2485" } ["NZD"]=> object(SimpleXMLElement)#104 (1) { [0]=> string(6) "1.6411" } ["PHP"]=> object(SimpleXMLElement)#107 (1) { [0]=> string(7) "61.6390" } ["PLN"]=> object(SimpleXMLElement)#110 (1) { [0]=> string(6) "4.1865" } ["RON"]=> object(SimpleXMLElement)#113 (1) { [0]=> string(6) "4.5183" } ["RUB"]=> object(SimpleXMLElement)#116 (1) { [0]=> string(7) "49.7510" } ["SEK"]=> object(SimpleXMLElement)#119 (1) { [0]=> string(6) "8.8603" } ["SGD"]=> object(SimpleXMLElement)#122 (1) { [0]=> string(6) "1.7469" } ["THB"]=> object(SimpleXMLElement)#125 (1) { [0]=> string(7) "44.6290" } ["TRY"]=> object(SimpleXMLElement)#128 (1) { [0]=> string(6) "3.0520" } ["USD"]=> object(SimpleXMLElement)#131 (1) { [0]=> string(6) "1.3768" } ["ZAR"]=> object(SimpleXMLElement)#134 (1) { [0]=> string(7) "14.9180" } }
Output for 5.1.0 - 5.1.1
array(32) { ["AUD"]=> object(SimpleXMLElement)#37 (1) { [0]=> string(6) "1.5392" } ["BGN"]=> object(SimpleXMLElement)#36 (1) { [0]=> string(6) "1.9558" } ["BRL"]=> object(SimpleXMLElement)#38 (1) { [0]=> string(6) "3.2100" } ["CAD"]=> object(SimpleXMLElement)#39 (1) { [0]=> string(6) "1.5244" } ["CHF"]=> object(SimpleXMLElement)#40 (1) { [0]=> string(6) "1.2172" } ["CNY"]=> object(SimpleXMLElement)#41 (1) { [0]=> string(6) "8.4564" } ["CZK"]=> object(SimpleXMLElement)#42 (1) { [0]=> string(7) "27.3690" } ["DKK"]=> object(SimpleXMLElement)#43 (1) { [0]=> string(6) "7.4627" } ["GBP"]=> object(SimpleXMLElement)#44 (1) { [0]=> string(6) "0.8246" } ["HKD"]=> object(SimpleXMLElement)#45 (1) { [0]=> string(7) "10.6847" } ["HRK"]=> object(SimpleXMLElement)#46 (1) { [0]=> string(6) "7.6525" } ["HUF"]=> object(SimpleXMLElement)#47 (1) { [0]=> string(8) "311.1500" } ["IDR"]=> object(SimpleXMLElement)#48 (1) { [0]=> string(10) "15957.1100" } ["ILS"]=> object(SimpleXMLElement)#49 (1) { [0]=> string(6) "4.8055" } ["INR"]=> object(SimpleXMLElement)#50 (1) { [0]=> string(7) "85.1757" } ["JPY"]=> object(SimpleXMLElement)#51 (1) { [0]=> string(8) "140.2000" } ["KRW"]=> object(SimpleXMLElement)#52 (1) { [0]=> string(9) "1474.4700" } ["LTL"]=> object(SimpleXMLElement)#53 (1) { [0]=> string(6) "3.4528" } ["MXN"]=> object(SimpleXMLElement)#54 (1) { [0]=> string(7) "18.2977" } ["MYR"]=> object(SimpleXMLElement)#55 (1) { [0]=> string(6) "4.5049" } ["NOK"]=> object(SimpleXMLElement)#56 (1) { [0]=> string(6) "8.2485" } ["NZD"]=> object(SimpleXMLElement)#57 (1) { [0]=> string(6) "1.6411" } ["PHP"]=> object(SimpleXMLElement)#58 (1) { [0]=> string(7) "61.6390" } ["PLN"]=> object(SimpleXMLElement)#59 (1) { [0]=> string(6) "4.1865" } ["RON"]=> object(SimpleXMLElement)#60 (1) { [0]=> string(6) "4.5183" } ["RUB"]=> object(SimpleXMLElement)#61 (1) { [0]=> string(7) "49.7510" } ["SEK"]=> object(SimpleXMLElement)#62 (1) { [0]=> string(6) "8.8603" } ["SGD"]=> object(SimpleXMLElement)#63 (1) { [0]=> string(6) "1.7469" } ["THB"]=> object(SimpleXMLElement)#64 (1) { [0]=> string(7) "44.6290" } ["TRY"]=> object(SimpleXMLElement)#65 (1) { [0]=> string(6) "3.0520" } ["USD"]=> object(SimpleXMLElement)#66 (1) { [0]=> string(6) "1.3768" } ["ZAR"]=> object(SimpleXMLElement)#67 (1) { [0]=> string(7) "14.9180" } }
Output for 5.0.0 - 5.0.5
Fatal error: Call to undefined method SimpleXMLElement::registerXPathNamespace() in /in/4Aphu on line 50
Process exited with code 255.
Output for 4.3.2 - 4.4.1, 4.4.3 - 4.4.9
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/4Aphu on line 48
Process exited with code 255.
Output for 4.4.2
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/4Aphu on line 49
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: simplexmlelement in /in/4Aphu on line 48