我有一个 CSV 文件,其中包含我要下载图像的 URL 列表。所以问题是如何逐行读取 CSV 文件并在每个 URL 上运行我的代码。
我有 links.csv 文件
url1.com
url2.com
url3.com
这是我要运行的代码
$results_page = curl($url);
$img_url = scrape_between($results_page, "\"mainUrl\":\"", "\",\"dimensions\"");
$title = scrape_between($results_page, "<span id=\"productTitle\" class=\"a-size-large\">", "</span>");
$find = array('/ /', '/:/');
$replace = array('_', '');
$img_name = preg_replace($find, $replace, $title);
$data = curl($img_url);
file_put_contents('images/'.$img_name.'.jpg', $data);
谢谢!
最佳答案
$fileData=fopen($file,'r');
while($row=fgets($fileData)){
// can parse further $row by usingstr_getcsv
echo $row."\n";
}
关于PHP逐行读取CSV文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22808978/