通过 URL 解析 API CSV [英] Parse API CSV via URL

查看:29
本文介绍了通过 URL 解析 API CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有关处理 API 数据的建议.我想知道解析具有以下 URL 格式的 csv 文件的最佳方法是什么.

I need advice on dealing with API data. I want to know what's the best approach to parse a csv file with the format of the URL below.

网址:网址...com../..api/..csv/..1234apikey=..123456ABC

URL: URL…com../..api/..csv/..1234apikey=..123456ABC

我想处理结果并将值插入到数据库中.

I would like to process the results and insert the values into a database.

数据会随着时间的推移而变化,因此实现需要是动态的.

The data will change overtime, so the implementation needs to be dynamic.

数据格式如下:

"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"

推荐答案

编辑 - 我不知道你不知道如何从 API 中提取数据.我会使用 file_get_contents() 或 CURL 来查询 URL.通常

Edit - I didn't know you didn't know how to pull data from the API. I would use file_get_contents() or CURL to query the URL. Typically

file_get_contents("URL: URL…com../..api/..csv/..1234apikey=..123456ABC");

我会通过用\n"分割然后用,"分割来循环数据.在 foreach 中,您可以将其放入 MySQL 表或任何您想做的事情.

I would loop the data by splitting by "\n" and then split it by ",". In the foreach you could then drop it into a MySQL table or whatever you want to do.

<?php

$data = "your api data";
$splitlines = explode("\n",$data);

foreach($splitlines as $line)
{
	$linedata = explode(',',$line);
	$position = $linedata[0];
	$player = $linedata[1];
	... etc.
}

这篇关于通过 URL 解析 API CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆