Home >php教程 >php手册 >php获取文件内容最后一行示例

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

WBOY
WBOYOriginal
2016-06-06 20:25:441362browse

这篇文章主要介绍了使用php获取文件内容最后一行的方法,大家参考使用吧

复制代码 代码如下:


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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn