How do I open a file from line X to line Y in PHP?

后端 未结 7 1344
情书的邮戳
情书的邮戳 2020-11-29 13:09

The closest I\'ve seen in the PHP docs, is to fread() a given length, but that doesnt specify which line to start from. Any other suggestions?

7条回答
  •  难免孤独
    2020-11-29 14:12

    You not going to be able to read starting from line X because lines can be of arbitrary length. So you will have to read from the start counting the number of lines read to get to line X. For example:

    = $startLine) {
            echo $line;
        }
        if ($lineNo == $endLine) {
            break;
        }
    }
    fclose($f);
    

提交回复
热议问题