PHP读取文件指定行的内容

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq285744011/article/details/82980219
function getLine($file, $line, $length = 40960){
    $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;
}

猜你喜欢

转载自blog.csdn.net/qq285744011/article/details/82980219
今日推荐