PHP获取文件中指定行数的数据
/**
* 获取指定行内容
*
* @param $file 文件路径
* @param $line 行数
* @param $length 指定行返回内容长度
*/
function get_line($file, $line, $length = 1000){
$returnTxt = null; // 初始化返回
$i = 1; // 行数
$handle = @fopen($file, "r");
if ($handle) {
while (!feof($handle)) {
$buffer = fgets($handle, $length);
if($line == $i) $returnTxt = $buffer;
$i++;
}
fclose($handle);
}
return $returnTxt;
}