当前位置: 编程技术>php
php获取文件内容最后一行示例
来源: 互联网 发布时间:2014-08-26
本文导语: 代码如下:$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;
代码如下:
$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;