这些代码是读取远程托管的csv文件、下载其内容并将其存储到本地 csv 文件的快速方法。保存文件后,打开文件循环遍历数据并显示它。同样,这可用于将数据导入数据库。

通过使用 cron 作业调用脚本来完成日常任务。

//collect the remote csv file
$csv = file_get_contents('https://www.q9ym.com/test.csv');

//save the data to a local csv file
file_put_contents('data.csv', $csv);

//open the local csv file
$handle = fopen('data.csv', "r");

//loop through the records
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
    for ($c=0; $c < 1; $c++) {

        //view the data
        print_r($data);

    }
}

//close the file
fclose($handle);

 

发表回复

您的电子邮箱地址不会被公开。