PHP 網路讀取CSV檔案指令[http->fopen ; https->file_get_contents]
PHP 網路讀取CSV檔案指令[http->fopen ; https->file_get_contents]
資料來源:https://github.com/jash-git/TW_save_stock-windows_cmd-
//https->file_get_contents
$csvData = file_get_contents(‘https://github.com/jash-git/TW_save_stock-windows_cmd-/blob/master/stock.csv?raw=true’, true);
$lines = preg_split(‘/\n|\r\n?/’, $csvData);//字串換行 分割(切割)
foreach ($lines as $line)
{
$data=explode(‘,’, $line);//PHP 字串切割
print_r($datas);//PHP 印出陣列
}
//http->fopen
$fp = fopen(“http://jashliao.eu/tools/save_stock/stock.csv”, “r”);
while (($data = fgetcsv($fp, 1000, “,”)) !== FALSE)
{
print_r($data);//PHP 印出陣列
}