如何在 PHP 中只读取文本文件最后 5 行?
要只读取文本文件的最后 5 行,代码如下 −
示例
$file = file("filename.txt");
for ($i = max(0, count($file)-6); $i < count($file); $i++) {
echo $file[$i] . "
";
}输出
将产生以下输出 −
Given that the file has more than 5 lines of text, the last 5 lines of the text file will be displayed.
打开文件并计算文件中行的数量,然后从最后一行开始读取 5 行。
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP