PHP,使用fgets跳过文本文件的第一行和最后一行

Ian*_*oar 3 php

我正在试图弄清楚如何在使用时阅读文本文件的第一行和最后一行fgets().第一行可以用a来解决if(!$firstLine),但我不知道如何忽略最后一行,或者我忽略第一行的解决方案是最佳选择.

fem*_*gon 8

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);
}
Run Code Online (Sandbox Code Playgroud)