我有一个包含多行逗号分隔值的文件。该文件的示例是:
1359739665,511251515,115151515,启动,1277771750,2215812581258,31.55.115.12,0,0 1359739665,511251515,115151515,恢复,1277771750,2215812581258,31.55.115.12,0,0 1359739665,511251515,115151515,恢复,1277771750, ,2215812581258,31.55.115.12,0,0 1359739665,511251515,115151515,结束,1277771750,,2215812581258,31.55.115.12,0,0
我基本上需要遍历每一行。目前,这是我的代码:
$file = "log.txt";
$contents = file_get_contents($file);
$fields = explode(',', $contents);
foreach ($fields as $row)
{
echo $row;
}
这适用于输出整个文件。但我的问题是如何一次迭代一行。每行基本上没有逗号结束,但我不知道如何在那里强制休息。我想做的是这个(即使代码不正确):
foreach ($fields as $row) //need $row to equal each row of the log
{
echo $row[0]; // will output 1359739665
echo $row[1]; // will output 511251515
etc...
}
谢谢!