我需要有关处理API数据的建议。我想知道用以下网址格式解析csv文件的最佳方法是什么。
网址:网址... com ../ .. api / .. csv / .. 1234apikey = .. 123456ABC
我想处理结果并将值插入数据库。
数据会随着时间而改变,因此实施需要是动态的。
数据格式如下:
"position","player.href","name.text","total","letter","days","hits","index","url"
"1","javascript:void(0);","Jamie","1","url"
"T2","javascript:void(0);","Tom","3","A","1","68","url"
"T2","javascript:void(0);","Sam","3","A","2","8","27","3","url"
"T2","javascript:void(0);","Joe","3","A","3","7","27","4","url"
"5","javascript:void(0);","Pat","2","A","4","7","28","5","url"
"T6","javascript:void(0);","Sean","1","A","5","6","29","6","url"
答案 0 :(得分:0)
编辑 - 我不知道你不知道如何从API中提取数据。我会使用file_get_contents()或CURL来查询URL。通常
file_get_contents("URL: URL…com../..api/..csv/..1234apikey=..123456ABC");

我会通过" \ n"来分割数据。然后用","分割它。在foreach中,您可以将其放入MySQL表或任何您想要做的事情。
<?php
$data = "your api data";
$splitlines = explode("\n",$data);
foreach($splitlines as $line)
{
$linedata = explode(',',$line);
$position = $linedata[0];
$player = $linedata[1];
... etc.
}
&#13;