【发布时间】:2015-09-30 08:18:48
【问题描述】:
我正在从 CSV 编写以下代码来获取股票数据,当我下载了字符串后,它会按以下方式拆分它
<COMPANY NAME>,<STOCK PRICE>,<STOCK CHANGE>
<COMPANY2 NAME>,<STOCK PRICE2>,<STOCK CHANGE2>
我尝试使用 PHP 函数 explode 使用 /n 字符来拆分数组。但是,这并没有正确拆分它。这是我的代码:
public function getQuotes()
{
$result = array();
$format = $this->format;
$stockString = "";
foreach ($this->stocks as $stock)
{
$stockString = $stockString . $stock . "+";
}
//Remove the last "+"
$stockString = substr($stockString,0,strlen($stockString)-1);
$s = file_get_contents("http://finance.yahoo.com/d/quotes.csv?s=". $stockString . "&f=" . $format . "&e=.csv");
//The splitting is to be done here.
}
}
提前谢谢你
【问题讨论】:
-
你试过正则表达式吗?