我有以下peoplelist.txt
文本文件,包含2行:
1,喂,喂@ me.com,老板
2,Hello Hello,hello2 @ me.com,Boss
我输出的代码是:
$handle = fopen("peoplelist.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
echo $line;
}
fclose($handle);
}
是否可能不输出整行,我只输出第二列中的数据(又名Hello
& Hello Again
)?
答案 0 :(得分:3)
因为那是CSV数据:
while (($line = fgetcsv($handle)) !== false) {
echo $line[1];
}
答案 1 :(得分:-1)
$handle = fopen("/temp/peoplelist.txt", "r");
if ($handle) {
while (($line = fgets($handle)) !== false) {
$parts = explode(',',$line);
echo $parts[1] . PHP_EOL;
}
fclose($handle);
}