獲取文件指定行數的內容

// 獲取文件指定行數的內容
function getFileLineHandle($fileName, $linePosition)
{
    $f = new \SplFileObject($fileName, 'r');
    $f->seek($linePosition);
    try {
        $content = $f->getCurrentLine();
        //$f->next();
    } catch (Exception $e) {
        // 如果行數超過文件總行數,獲取異常
        $content = '';
    }

    return $content;
}
相關文章
相關標籤/搜索