$c = getLine("./a.txt", 10); // 讀取a.txt檔案第10行內容
echo $c;
/**
* 獲取指定行內容
*
* @param $file 檔案路徑
* @param $line 行數
* @param $length 指定行返回內容長度
*/
function getLine($file, $line, $length = 4096){
$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;
$c = getLine("./a.txt", 10); // 讀取a.txt檔案第10行內容
echo $c;
/**
* 獲取指定行內容
*
* @param $file 檔案路徑
* @param $line 行數
* @param $length 指定行返回內容長度
*/
function getLine($file, $line, $length = 4096){
$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;
}