从文本文件读取特定行 [英] Reading a specific line from a text file
本文介绍了从文本文件读取特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
使用PHP在大型文件中获取一行
Possible Duplicate:
Getting one line in a huge file with PHP
我有一个大约200行的文件文本,我想从该文本文件中读取特定的行.我该怎么办?
I have a file text with something like 200 lines and I want to read a specific line from this text file. how can I do it?
谢谢.
推荐答案
未经测试.
function getline($file, $linenum, $linelen = 8192) {
$handle = fopen($file, "r");
if ($handle) {
while (!feof($handle)) {
$linenum -= 1;
$buffer = fgets($handle, $linelen); // Read a line.
if (!$linenum) return $buffer;
}
fclose($handle); // Close the file.
}
return -1;
}
这篇关于从文本文件读取特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文