<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file));
}
fclose($file);
?>
CSV 文件:
George, John, Thomas, USA
James, Adrew, Martin, USA
输出类似:
Array
(
[0] => George
[1] => John
[2] => Thomas
[3] => USA
Array
(
[0] => James
[1] => Adrew
[2] => Martin
[3] => USA
)
但是php文件改成,只想输出第一列的,就只能解析一个George,不知道为什么
<?php
$file = fopen("contacts.csv","r");
while(! feof($file))
{
print_r(fgetcsv($file)[0]);
}
fclose($file);
?>
这行的意思是读取一行,转成 php 数组,取出数组第一个元素。