php获取文件内容最后一行示例
程序员文章站
2023-11-20 22:57:46
复制代码 代码如下:$rs = 'readme.md';$fp = fopen($rs, 'r');
fseek($fp,-1,seek_end);
$s = '';w...
复制代码 代码如下:
$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;