PHP逐行读取CSV文件 [英] PHP read CSV file line by lines
本文介绍了PHP逐行读取CSV文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个从URL加载的CSV文件,我想用PHP遍历所有行.
I have a CSV file loaded from an URL, and I want to loop over the lines with PHP.
这是此CSV的典型行:
Here is a typical line of this CSV:
1004000018;active;"TEST1";"TEST2";"TEST3";"TEST4"
我想得到每一行的结果:
I would like to get this result, for each row:
1004000018
active
TEST1
TEST2
TEST3
TEST4
推荐答案
您可以使用php函数 fgetcsv ,它应该可以工作:
You can achieve this using the php function fgetcsv, this should work :
PHP
$file = fopen('file.csv', 'r');
while (($line = fgetcsv($file)) !== FALSE) {
//$line[0] = '1004000018' in first iteration
print_r($line);
}
fclose($file);
这篇关于PHP逐行读取CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文