Edit: I’ve learned much since the posting of this question, and so I have rewritten it for anyone who similarly inquires.
I’m attempting to load a specified number of lines from the end of a text file via a HTTP GET request, which will be sent to a PHP file. Can this be done with file_get_contents()?
The function file_get_contents() also reads the entire file into memory. What is a more efficient solution than reading the entire file to array, then removing the specified number of lines?
For example, if I had a 12000 line text file, how would I read the range of lines between 4025-6042?
You would use
file()to get the file as an array. Thenarray_slice()to prune the array.