Home >Backend Development >PHP Tutorial >php获取文件内容最后一行示例_PHP

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

WBOY
WBOYOriginal
2016-06-01 11:57:251864browse

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