php获取文件内容最后一行示例_PHP教程
程序员文章站
2022-04-16 15:02:19
...
复制代码 代码如下:
$rs = 'README.md';
$fp = fopen($rs, 'r');
fseek($fp,-1,SEEK_END);
$s = '';
while(($c = fgetc($fp)) !== false)
{
if($c == "\n" && $s) break;
$s = $c . $s;
fseek($fp, -2, SEEK_CUR);
}
fclose($fp);
echo $s;
exit;