@ 2014-03-05T00:12:36Z <?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();
$currencies[ trim( $attributes['currency'] ) ] = trim( $attributes['rate'] );
/*if ( isset( $attributes['currency'], $attributes['rate'] ) )
{
$currencies[ trim( $attributes['currency'] ) ] = trim( $attributes['rate'] );
}*/
}
var_dump( $currencies );
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Output for 8.1.0 - 8.1.28 , 8.2.0 - 8.2.18 , 8.3.0 - 8.3.6 Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/WriQ2 on line 60
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/WriQ2 on line 60
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/WriQ2 on line 60
Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /in/WriQ2 on line 60
array(33) {
[""]=>
string(0) ""
["AUD"]=>
string(6) "1.5392"
["BGN"]=>
string(6) "1.9558"
["BRL"]=>
string(6) "3.2100"
["CAD"]=>
string(6) "1.5244"
["CHF"]=>
string(6) "1.2172"
["CNY"]=>
string(6) "8.4564"
["CZK"]=>
string(7) "27.3690"
["DKK"]=>
string(6) "7.4627"
["GBP"]=>
string(6) "0.8246"
["HKD"]=>
string(7) "10.6847"
["HRK"]=>
string(6) "7.6525"
["HUF"]=>
string(8) "311.1500"
["IDR"]=>
string(10) "15957.1100"
["ILS"]=>
string(6) "4.8055"
["INR"]=>
string(7) "85.1757"
["JPY"]=>
string(8) "140.2000"
["KRW"]=>
string(9) "1474.4700"
["LTL"]=>
string(6) "3.4528"
["MXN"]=>
string(7) "18.2977"
["MYR"]=>
string(6) "4.5049"
["NOK"]=>
string(6) "8.2485"
["NZD"]=>
string(6) "1.6411"
["PHP"]=>
string(7) "61.6390"
["PLN"]=>
string(6) "4.1865"
["RON"]=>
string(6) "4.5183"
["RUB"]=>
string(7) "49.7510"
["SEK"]=>
string(6) "8.8603"
["SGD"]=>
string(6) "1.7469"
["THB"]=>
string(7) "44.6290"
["TRY"]=>
string(6) "3.0520"
["USD"]=>
string(6) "1.3768"
["ZAR"]=>
string(7) "14.9180"
}
Output for 5.1.0 - 5.1.6 , 5.2.0 - 5.2.17 , 5.3.0 - 5.3.29 , 5.4.0 - 5.4.45 , 5.5.0 - 5.5.35 , 5.6.0 - 5.6.28 , 7.0.0 - 7.0.20 , 7.1.0 - 7.1.20 , 7.2.29 - 7.2.33 , 7.3.12 - 7.3.33 , 7.4.0 - 7.4.33 , 8.0.0 - 8.0.30 array(33) {
[""]=>
string(0) ""
["AUD"]=>
string(6) "1.5392"
["BGN"]=>
string(6) "1.9558"
["BRL"]=>
string(6) "3.2100"
["CAD"]=>
string(6) "1.5244"
["CHF"]=>
string(6) "1.2172"
["CNY"]=>
string(6) "8.4564"
["CZK"]=>
string(7) "27.3690"
["DKK"]=>
string(6) "7.4627"
["GBP"]=>
string(6) "0.8246"
["HKD"]=>
string(7) "10.6847"
["HRK"]=>
string(6) "7.6525"
["HUF"]=>
string(8) "311.1500"
["IDR"]=>
string(10) "15957.1100"
["ILS"]=>
string(6) "4.8055"
["INR"]=>
string(7) "85.1757"
["JPY"]=>
string(8) "140.2000"
["KRW"]=>
string(9) "1474.4700"
["LTL"]=>
string(6) "3.4528"
["MXN"]=>
string(7) "18.2977"
["MYR"]=>
string(6) "4.5049"
["NOK"]=>
string(6) "8.2485"
["NZD"]=>
string(6) "1.6411"
["PHP"]=>
string(7) "61.6390"
["PLN"]=>
string(6) "4.1865"
["RON"]=>
string(6) "4.5183"
["RUB"]=>
string(7) "49.7510"
["SEK"]=>
string(6) "8.8603"
["SGD"]=>
string(6) "1.7469"
["THB"]=>
string(7) "44.6290"
["TRY"]=>
string(6) "3.0520"
["USD"]=>
string(6) "1.3768"
["ZAR"]=>
string(7) "14.9180"
}
Output for 5.0.0 - 5.0.5 <br />
<b>Fatal error</b>: Call to undefined method SimpleXMLElement::registerXPathNamespace() in <b>/in/WriQ2</b> on line <b>50</b><br />
Process exited with code 255 . Output for 4.3.2 - 4.3.11 , 4.4.0 - 4.4.1 , 4.4.3 - 4.4.9 <br />
<b>Fatal error</b>: Cannot instantiate non-existent class: simplexmlelement in <b>/in/WriQ2</b> on line <b>48</b><br />
Process exited with code 255 . Output for 4.4.2 <br />
<b>Fatal error</b>: Cannot instantiate non-existent class: simplexmlelement in <b>/in/WriQ2</b> on line <b>49</b><br />
Process exited with code 255 . Output for 4.3.0 - 4.3.1 <br />
<b>Fatal error</b>: Cannot instantiate non-existent class: simplexmlelement in <b>/in/WriQ2</b> on line <b>48</b><br />
preferences:dark mode live preview
240.76 ms | 401 KiB | 343 Q