[英]PHP read CSV file line by line
我有一個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";
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.