时间:2021-07-01 10:21:17 帮助过:17人阅读
可以用 fseek 指定最后位置,然后往前读。
比如 fseek($fp,-1,SEEK_END);就跑到倒数第一行了
20130721 2.02M 20130722 2.02M 20130723 2.02M 20130724 2.02M 20130725 2.02M 20130726 2.02M 20130727 2.02M 20130728 2.02M 20130729 2.02M 20130730 2.02M 20130731 2.02M 20130801 2.02M
$fn = '你的文本文件名';$fp = fopen($fn, '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;
如果文件不是巨大,正读也很方便
$fp = fopen($fn, 'r');while($buf = fgets($fp)) $res = $buf;fclose($fp);echo $res;