Code: Select all
Array ( [name] => gesmes:Envelope [attributes] => Array ( [xmlns:gesmes] => http://www.gesmes.org/xml/2002-08-01 [xmlns] => http://www.ecb.int/vocabulary/2002-08-01/eurofxref ) [content] => [children] => Array ( [0] => Array ( [name] => gesmes:subject [attributes] => [content] => Reference rates ) [1] => Array ( [name] => gesmes:Sender [attributes] => [content] => [children] => Array ( [0] => Array ( [name] => gesmes:name [attributes] => [content] => European Central Bank ) ) ) [2] => Array ( [name] => Cube [attributes] => [content] => [children] => Array ( [0] => Array ( [name] => Cube [attributes] => Array ( [time] => 2009-02-23 ) [content] => [children] => Array ( [0] => Array ( [name] => Cube [attributes] => Array ( [currency] => USD [rate] => 1.2798 ) [content] => ) [1] => Array ( [name] => Cube [attributes] => Array ( [currency] => JPY [rate] => 121.09 ) [content] => ) [2] => Array ( [name] => Cube [attributes] => Array ( [currency] => BGN [rate] => 1.9558 ) [content] => ) [3] => Array ( [name] => Cube [attributes] => Array ( [currency] => CZK [rate] => 28.451 ) [content] => ) [4] => Array ( [name] => Cube [attributes] => Array ( [currency] => DKK [rate] => 7.4504 ) [content] => ) [5] => Array ( [name] => Cube [attributes] => Array ( [currency] => EEK [rate] => 15.6466 ) [content] => ) [6] => Array ( [name] => Cube [attributes] => Array ( [currency] => GBP [rate] => 0.87800 ) [content] => ) [7] => Array ( [name] => Cube [attributes] => Array ( [currency] => HUF [rate] => 297.05 ) [content] => ) [8] => Array ( [name] => Cube [attributes] => Array ( [currency] => LTL [rate] => 3.4528 ) [content] => ) [9] => Array ( [name] => Cube [attributes] => Array ( [currency] => LVL [rate] => 0.7070 ) [content] => ) [10] => Array ( [name] => Cube [attributes] => Array ( [currency] => PLN [rate] => 4.6435 ) [content] => ) [11] => Array ( [name] => Cube [attributes] => Array ( [currency] => RON [rate] => 4.2822 ) [content] => ) [12] => Array ( [name] => Cube [attributes] => Array ( [currency] => SEK [rate] => 11.1350 ) [content] => ) [13] => Array ( [name] => Cube [attributes] => Array ( [currency] => CHF [rate] => 1.4908 ) [content] => ) [14] => Array ( [name] => Cube [attributes] => Array ( [currency] => NOK [rate] => 8.7190 ) [content] => ) [15] => Array ( [name] => Cube [attributes] => Array ( [currency] => HRK [rate] => 7.4617 ) [content] => ) [16] => Array ( [name] => Cube [attributes] => Array ( [currency] => RUB [rate] => 46.0205 ) [content] => ) [17] => Array ( [name] => Cube [attributes] => Array ( [currency] => TRY [rate] => 2.1552 ) [content] => ) [18] => Array ( [name] => Cube [attributes] => Array ( [currency] => AUD [rate] => 1.9796 ) [content] => ) [19] => Array ( [name] => Cube [attributes] => Array ( [currency] => BRL [rate] => 3.0459 ) [content] => ) [20] => Array ( [name] => Cube [attributes] => Array ( [currency] => CAD [rate] => 1.6001 ) [content] => ) [21] => Array ( [name] => Cube [attributes] => Array ( [currency] => CNY [rate] => 8.7487 ) [content] => ) [22] => Array ( [name] => Cube [attributes] => Array ( [currency] => HKD [rate] => 9.9226 ) [content] => ) [23] => Array ( [name] => Cube [attributes] => Array ( [currency] => IDR [rate] => 15255.22 ) [content] => ) [24] => Array ( [name] => Cube [attributes] => Array ( [currency] => INR [rate] => 63.7660 ) [content] => ) [25] => Array ( [name] => Cube [attributes] => Array ( [currency] => KRW [rate] => 1910.81 ) [content] => ) [26] => Array ( [name] => Cube [attributes] => Array ( [currency] => MXN [rate] => 18.8611 ) [content] => ) [27] => Array ( [name] => Cube [attributes] => Array ( [currency] => MYR [rate] => 4.6783 ) [content] => ) [28] => Array ( [name] => Cube [attributes] => Array ( [currency] => NZD [rate] => 2.4967 ) [content] => ) [29] => Array ( [name] => Cube [attributes] => Array ( [currency] => PHP [rate] => 61.370 ) [content] => ) [30] => Array ( [name] => Cube [attributes] => Array ( [currency] => SGD [rate] => 1.9537 ) [content] => ) [31] => Array ( [name] => Cube [attributes] => Array ( [currency] => THB [rate] => 45.593 ) [content] => ) [32] => Array ( [name] => Cube [attributes] => Array ( [currency] => ZAR [rate] => 12.7708 ) [content] => ) ) ) ) ) ) )Code: Select all
Array
(
[name] => gesmes:Envelope
[attributes] => Array
(
[xmlns:gesmes] => http://www.gesmes.org/xml/2002-08-01
[xmlns] => http://www.ecb.int/vocabulary/2002-08-01/eurofxref
)
[content] =>
[children] => Array
(
[0] => Array
(
[name] => gesmes:subject
[attributes] =>
[content] => Reference rates
)
[1] => Array
(
[name] => gesmes:Sender
[attributes] =>
[content] =>
[children] => Array
(
[0] => Array
(
[name] => gesmes:name
[attributes] =>
[content] => European Central Bank
)
)
)
[2] => Array
(
[name] => Cube
[attributes] =>
[content] =>
[children] => Array
(
[0] => Array
(
[name] => Cube
[attributes] => Array
(
[time] => 2009-02-23
)
[content] =>
[children] => Array
(
[0] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => USD
[rate] => 1.2798
)
[content] =>
)
[1] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => JPY
[rate] => 121.09
)
[content] =>
)
[2] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => BGN
[rate] => 1.9558
)
[content] =>
)
[3] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => CZK
[rate] => 28.451
)
[content] =>
)
[4] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => DKK
[rate] => 7.4504
)
[content] =>
)
[5] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => EEK
[rate] => 15.6466
)
[content] =>
)
[6] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => GBP
[rate] => 0.87800
)
[content] =>
)
[7] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => HUF
[rate] => 297.05
)
[content] =>
)
[8] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => LTL
[rate] => 3.4528
)
[content] =>
)
[9] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => LVL
[rate] => 0.7070
)
[content] =>
)
[10] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => PLN
[rate] => 4.6435
)
[content] =>
)
[11] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => RON
[rate] => 4.2822
)
[content] =>
)
[12] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => SEK
[rate] => 11.1350
)
[content] =>
)
[13] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => CHF
[rate] => 1.4908
)
[content] =>
)
[14] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => NOK
[rate] => 8.7190
)
[content] =>
)
[15] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => HRK
[rate] => 7.4617
)
[content] =>
)
[16] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => RUB
[rate] => 46.0205
)
[content] =>
)
[17] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => TRY
[rate] => 2.1552
)
[content] =>
)
[18] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => AUD
[rate] => 1.9796
)
[content] =>
)
[19] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => BRL
[rate] => 3.0459
)
[content] =>
)
[20] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => CAD
[rate] => 1.6001
)
[content] =>
)
[21] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => CNY
[rate] => 8.7487
)
[content] =>
)
[22] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => HKD
[rate] => 9.9226
)
[content] =>
)
[23] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => IDR
[rate] => 15255.22
)
[content] =>
)
[24] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => INR
[rate] => 63.7660
)
[content] =>
)
[25] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => KRW
[rate] => 1910.81
)
[content] =>
)
[26] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => MXN
[rate] => 18.8611
)
[content] =>
)
[27] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => MYR
[rate] => 4.6783
)
[content] =>
)
[28] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => NZD
[rate] => 2.4967
)
[content] =>
)
[29] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => PHP
[rate] => 61.370
)
[content] =>
)
[30] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => SGD
[rate] => 1.9537
)
[content] =>
)
[31] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => THB
[rate] => 45.593
)
[content] =>
)
[32] => Array
(
[name] => Cube
[attributes] => Array
(
[currency] => ZAR
[rate] => 12.7708
)
[content] =>
)
)
)
)
)
)
)I would like to set in variables a few rates from this array but I do not know how to do it.
Like, what is the route to a rate value for example? I am struggling to find the route.
This is the function:
Code: Select all
<?php
function xml_to_array( $file )
{
$parser = xml_parser_create();
xml_parser_set_option( $parser, XML_OPTION_CASE_FOLDING, 0 );
xml_parser_set_option( $parser, XML_OPTION_SKIP_WHITE, 1 );
xml_parse_into_struct( $parser, file_get_contents($file), $tags );
xml_parser_free( $parser );
$elements = array();
$stack = array();
foreach ( $tags as $tag )
{
$index = count( $elements );
if ( $tag['type'] == "complete" || $tag['type'] == "open" )
{
$elements[$index] = array();
$elements[$index]['name'] = $tag['tag'];
$elements[$index]['attributes'] = $tag['attributes'];
$elements[$index]['content'] = $tag['value'];
if ( $tag['type'] == "open" )
{ # push
$elements[$index]['children'] = array();
$stack[count($stack)] = &$elements;
$elements = &$elements[$index]['children'];
}
}
if ( $tag['type'] == "close" )
{ # pop
$elements = &$stack[count($stack) - 1];
unset($stack[count($stack) - 1]);
}
}
return $elements[0];
}
$lero = xml_to_array('http://www.ecb.int/stats/eurofxref/eurofxref-daily.xml');
echo '<pre>';
print_r($lero);
echo '</pre>';
?>Code: Select all
$ratea = thevalueinarrayaboveforusd;
$rateb = thevalueinarrayaboveforjpy;
$ratec = thevalueinarrayaboveforgbp;
$rated = thevalueinarrayaboveforcad;
$ratee = thevalueinarrayaboveforeur;
$ratef = thevalueinarrayaboveforaud;