试图从谷歌股票 api 中提取一些数据。所以只是试图提取它。
$t=time();
echo(date("H:i",$t))."<br><br>";
$xml="http://www.google.com/ig/api?stock=KNEBV&stock=FUM1V";
$xml = json_decode(json_encode((array) simplexml_load_file($xml)), 1);
echo '<pre>';
print_r($xml);
echo '</pre>';
?>
这给了我下面的输出。但我似乎无法获得任何价值。我迷失在数据中,不知道从哪一端开始。
我假设$xml-> finance[0]->symbol会给我“ FUM1V ”,而$xml-> Finance[1]->symbol会给我KNEBV但无论我尝试什么组合,我都会得到空白。好的,这可能是一个不好的例子,但在翻译中丢失了。
关于如何“循环”并打印每个符号和一些值的任何想法?
Array
(
[@attributes] => Array
(
[version] => 1
)
[finance] => Array
(
[0] => Array
(
[@attributes] => Array
(
[module_id] => 0
[tab_id] => 0
[mobile_row] => 0
[mobile_zipped] => 1
[row] => 0
[section] => 0
)
[symbol] => Array
(
[@attributes] => Array
(
[data] => FUM1V
)
)
[pretty_symbol] => Array
(
[@attributes] => Array
(
[data] => FUM1V
)
)
[symbol_lookup_url] => Array
(
[@attributes] => Array
(
[data] => /finance?client=ig&q=FUM1V
)
)
[company] => Array
(
[@attributes] => Array
(
[data] => Fortum Oyj
)
)
[exchange] => Array
(
[@attributes] => Array
(
[data] => HEL
)
)
[exchange_timezone] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[exchange_utc_offset] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[exchange_closing] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[divisor] => Array
(
[@attributes] => Array
(
[data] => 2
)
)
[currency] => Array
(
[@attributes] => Array
(
[data] => EUR
)
)
[last] => Array
(
[@attributes] => Array
(
[data] => 14.68
)
)
[high] => Array
(
[@attributes] => Array
(
[data] => 14.77
)
)
[low] => Array
(
[@attributes] => Array
(
[data] => 14.59
)
)
[volume] => Array
(
[@attributes] => Array
(
[data] => 1216170
)
)
[avg_volume] => Array
(
[@attributes] => Array
(
[data] => 1607
)
)
[market_cap] => Array
(
[@attributes] => Array
(
[data] => 13041.22
)
)
[open] => Array
(
[@attributes] => Array
(
[data] => 14.60
)
)
[y_close] => Array
(
[@attributes] => Array
(
[data] => 14.59
)
)
[change] => Array
(
[@attributes] => Array
(
[data] => +0.09
)
)
[perc_change] => Array
(
[@attributes] => Array
(
[data] => 0.62
)
)
[delay] => Array
(
[@attributes] => Array
(
[data] => 0
)
)
[trade_timestamp] => Array
(
[@attributes] => Array
(
[data] => 5 hours ago
)
)
[trade_date_utc] => Array
(
[@attributes] => Array
(
[data] => 20130617
)
)
[trade_time_utc] => Array
(
[@attributes] => Array
(
[data] => 152953
)
)
[current_date_utc] => Array
(
[@attributes] => Array
(
[data] => 20130617
)
)
[current_time_utc] => Array
(
[@attributes] => Array
(
[data] => 212211
)
)
[symbol_url] => Array
(
[@attributes] => Array
(
[data] => /finance?client=ig&q=FUM1V
)
)
[chart_url] => Array
(
[@attributes] => Array
(
[data] => /finance/chart?q=HEL:FUM1V&tlf=12
)
)
[disclaimer_url] => Array
(
[@attributes] => Array
(
[data] => /help/stock_disclaimer.html
)
)
[ecn_url] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[isld_last] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[isld_trade_date_utc] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[isld_trade_time_utc] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[brut_last] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[brut_trade_date_utc] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[brut_trade_time_utc] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[daylight_savings] => Array
(
[@attributes] => Array
(
[data] => true
)
)
)
[1] => Array
(
[@attributes] => Array
(
[module_id] => 0
[tab_id] => 0
[mobile_row] => 0
[mobile_zipped] => 1
[row] => 0
[section] => 0
)
[symbol] => Array
(
[@attributes] => Array
(
[data] => KNEBV
)
)
[pretty_symbol] => Array
(
[@attributes] => Array
(
[data] => KNEBV
)
)
[symbol_lookup_url] => Array
(
[@attributes] => Array
(
[data] => /finance?client=ig&q=KNEBV
)
)
[company] => Array
(
[@attributes] => Array
(
[data] => KONE Corporation
)
)
[exchange] => Array
(
[@attributes] => Array
(
[data] => HEL
)
)
[exchange_timezone] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[exchange_utc_offset] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[exchange_closing] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[divisor] => Array
(
[@attributes] => Array
(
[data] => 2
)
)
[currency] => Array
(
[@attributes] => Array
(
[data] => EUR
)
)
[last] => Array
(
[@attributes] => Array
(
[data] => 65.95
)
)
[high] => Array
(
[@attributes] => Array
(
[data] => 67.00
)
)
[low] => Array
(
[@attributes] => Array
(
[data] => 65.95
)
)
[volume] => Array
(
[@attributes] => Array
(
[data] => 249502
)
)
[avg_volume] => Array
(
[@attributes] => Array
(
[data] => 303
)
)
[market_cap] => Array
(
[@attributes] => Array
(
[data] => 16911.31
)
)
[open] => Array
(
[@attributes] => Array
(
[data] => 66.10
)
)
[y_close] => Array
(
[@attributes] => Array
(
[data] => 66.05
)
)
[change] => Array
(
[@attributes] => Array
(
[data] => -0.10
)
)
[perc_change] => Array
(
[@attributes] => Array
(
[data] => -0.15
)
)
[delay] => Array
(
[@attributes] => Array
(
[data] => 0
)
)
[trade_timestamp] => Array
(
[@attributes] => Array
(
[data] => 5 hours ago
)
)
[trade_date_utc] => Array
(
[@attributes] => Array
(
[data] => 20130617
)
)
[trade_time_utc] => Array
(
[@attributes] => Array
(
[data] => 152952
)
)
[current_date_utc] => Array
(
[@attributes] => Array
(
[data] => 20130617
)
)
[current_time_utc] => Array
(
[@attributes] => Array
(
[data] => 212211
)
)
[symbol_url] => Array
(
[@attributes] => Array
(
[data] => /finance?client=ig&q=KNEBV
)
)
[chart_url] => Array
(
[@attributes] => Array
(
[data] => /finance/chart?q=HEL:KNEBV&tlf=12
)
)
[disclaimer_url] => Array
(
[@attributes] => Array
(
[data] => /help/stock_disclaimer.html
)
)
[ecn_url] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[isld_last] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[isld_trade_date_utc] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[isld_trade_time_utc] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[brut_last] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[brut_trade_date_utc] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[brut_trade_time_utc] => Array
(
[@attributes] => Array
(
[data] =>
)
)
[daylight_savings] => Array
(
[@attributes] => Array
(
[data] => true
)
)
)
)
)