I know I can read a file line-by-line with this function, and then I could just do something like if($line_no < $X) continue;, but I was wondering if there was anything more efficient? These could be some potentially large files I’m reading and I don’t want to stuff everything into a gigantic array, most of which I’m going to ignore.
I know I can read a file line-by-line with this function , and then
Share
PHP can’t jump to a specific line using line numbers only without additional processing. If you have the number of bytes to skip, you can simply use
fseek().If running out of memory simply using
file()is a concern, I can’t help you, but you can use:To get the lines after the desired line without adding anything unnecessary to memory. This should be relatively fast even on large files.
If that’s still not enough, you might want to consider using a different language.