使用php从文本文件中获取最后50行 [英] Get the last 50 lines from text file using php

查看:193
本文介绍了使用php从文本文件中获取最后50行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本文件,例如日志文件,我想从中获取最后50行.

I have a text file such as a log file, and I want to get the last 50 lines from that.

如何在PHP中做到这一点?

How can I do it, in PHP?

推荐答案

如果您使用的是Linux,我想您也可以使用"tail".

I guess you could also be using "tail" if you are on linux.

$handle = popen("tail -50l YOUR_FILE_HERE 2>&1", 'r');
while(!feof($handle)) {
    $buffer = fgets($handle);
    echo "$buffer<br/>\n";
    ob_flush();
    flush();
}
pclose($handle);

这篇关于使用php从文本文件中获取最后50行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆