当前位置:Gxlcms > PHP教程 > php获取文件内容最后一行示例_PHP教程

php获取文件内容最后一行示例_PHP教程

时间:2021-07-01 10:21:17 帮助过:6人阅读

代码如下:
$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;

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/676863.htmlTechArticle 代码如下:

$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; fs...

人气教程排行