Read a file backwards line by line using fseek

后端 未结 9 2033
温柔的废话
温柔的废话 2020-11-27 07:33

How do I read a file backwards line by line using fseek?

code can be helpful. must be cross platform and pure php.

many thanks in advance

regards

9条回答
  •  清酒与你
    2020-11-27 08:19

    You cannot fseek line by line, because you do not know how long the lines are until you read them.

    You should either read the whole file into a list of lines, or if the file is too big for that and you only need the last lines, read fixed-sized chunks from the end of the file and implement a bit more complicated logic which detects lines from such data.

提交回复
热议问题