[英]PHP - getting stock quotes online
I have a php file wherein im trying to get online data/stock quote that i would like to print in a html table line by line heres my code: 我有一个php文件,其中我试图获取在线数据/股票报价,我想在html表中逐行打印以下代码:
{
$url = 'http://download.finance.yahoo.com/d/quotes.csv?
s=^AORD+BHP.AX+BLT.L+AAPL&f=nd1l1';
$data = file_get_contents($url);
echo $data;
}
and the output is: "ALL ORDINARIES","9/7/2017",5753.80 "BHP BLT FPO","9/7/2017",27.33 "BHP BILLITON PLC ORD $0.50","9/7/2017",1457.50 "Apple Inc.","9/7/2017",161.26 输出为:“ ALL ORDINARIES”,“ 9/7/2017”,5753.80“ BHP BLT FPO”,“ 9/7/2017”,27.33“ BHP BILLITON PLC ORD $ 0.50”,“ 9/7/2017”, 1457.50“ Apple Inc。”,“ 9/7/2017”,161.26
what i would like to have is something like this: 我想拥有的是这样的:
"ALL ORDINARIES","9/7/2017",5753.80
"BHP BLT FPO","9/7/2017",27.33
"BHP BILLITON PLC ORD $0.50","9/7/2017",1457.50
"Apple Inc.","9/7/2017",161.26
i tried to do: 我试着做:
echo $data[1];
but result is: "A" 但结果是:“ A”
how should be my approach to this? 我应该如何处理? Thank you!
谢谢!
$data
is a string, not an array. $data
是字符串,而不是数组。 Use nl2br()
to convert the newlines in the data to HTML <br>
tags: 使用
nl2br()
将数据中的换行符转换为HTML <br>
标记:
echo nl2br($data);
Or print it in a <pre>
block to indicate that the data is formatted and shouldn't be wrapped by the browser. 或者将其打印在
<pre>
块中,以指示数据已格式化并且不应由浏览器包装。
echo '<pre>' . $data . '</pre>';
Currently, $data
is a string, which gives $data[0] == '"'; $data[1] == 'A'; $data[2] == 'L', $data[3] == 'L' ...
for the entire string. 当前,
$data
是一个字符串,它给出$data[0] == '"'; $data[1] == 'A'; $data[2] == 'L', $data[3] == 'L' ...
表示整个字符串。
Since you are pulling a csv
file, $data = str_getcsv($data)
will convert the string contained in $data
into an array. 由于您要提取的是
csv
文件,因此$data = str_getcsv($data)
会将$data
包含的字符串转换为数组。 See http://php.net/manual/en/function.str-getcsv.php . 参见http://php.net/manual/en/function.str-getcsv.php 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.