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

后端 未结 7 1342
情书的邮戳
情书的邮戳 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 13:57

    If you're looking for lines then you can't use fread because that relies on a byte offset, not the number of line breaks. You actually have to read the file to find the line breaks, so a different function is more appropriate. fgets will read the file line-by-line. Throw that in a loop and capture only the lines you want.

提交回复
热议问题