如何在 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