php - 下载一个csv文件直接到内存,最好没有cURL [英] php - download a csv file directly to the memory, preferably without cURL

查看:358
本文介绍了php - 下载一个csv文件直接到内存,最好没有cURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这等价于问题:将CSV直接下载到Python CSV解析器< a>但在php。基本上我正在寻找一个库提供接口能够做的事情我用python只是在几行代码:

This is equivalent of question: Download CSV directly into Python CSV parser but in php. Basically I'm looking for a library offering interface capable of doing things I do with python just in a few lines of code:

h = httplib2.Http('.cache')
url = 'http://financials.morningstar.com/ajax/ReportProcess4CSV.html?t=' + code + '&region=AUS&culture=en_us&reportType='+ report + '&period=12&dataType=A&order=asc&columnYear=5&rounding=1&view=raw&productCode=usa&denominatorView=raw&number=1'
headers, data = h.request(url)
return data

解析csv文件,但我想避免使用cURL及其低级接口。有任何建议吗?

I need to download and parse csv file but I would like to avoid using cURL and its low level interface. Any suggestions?

推荐答案

不是三行:

function getURL($url){
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}

或者我想你可以使用file_get_contents,如果你真的不喜欢cURL ...

Or I guess you could use file_get_contents, if you REALLY don't like cURL...

file_get_contents($url);

另请参阅 str_getcsv()用于将上述函数中的字符串转换为包含CSV文件中数据的数组。

Also, take a look at str_getcsv() for converting the strings from the above functions into an array with data from the CSV file.

这篇关于php - 下载一个csv文件直接到内存,最好没有cURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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