我正在尝试找出在使用 fgets()
阅读文本文件时如何跳过文本文件的第一行和最后一行。第一行可以用 if(!$firstLine)
解决,但我不确定如何忽略最后一行,或者我忽略第一行的解决方案是否是最佳选择。
最佳答案
fgets($file); //Ignore the first line
$line = fgets($file);
$next = fgets($file);
while ($next !== false) { //check the line after the one you will process next.
//This way, when $next is false, then you still have one line left you could process, the last line.
//Do Stuff
$line = $next;
$next = fgets($file);
}
关于PHP,使用fgets跳过文本文件的第一行和最后一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13637069/