PHP 逐行读取 CSV 文件


PHP read CSV file line by line

>我有一个CSV文件,其中包含我要下载图像的URL列表。所以问题是如何逐行读取 CSV 文件并在每个 URL 上运行我的代码。

我有链接.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";
   }