Considering i have a 100GB txt file containing millions of lines of text. How could i read this text file by block of lines using PHP?
i can\'t use file_get_
The fread
approach sounds like a reasonable solution. You can detect whether you've reached the end of a line by checking whether the final character in the string is a newline character ('\n'
). If it isn't, then you can either read some more characters and append them to your existing string, or you can trim characters from your string back to the last newline, and then use fseek
to adjust your position in the file.
Side point: Are you aware that reading a 100GB file will take a very long time?