I would like to know which is the fastest way to find a string in a file using PHP. I have been told than the quickest way to read a file was using file()
function, but to find a string in the whole file I will have to do a foreach. Whereas if I use file_get_contents
or something, I just have to do a strpos()
on the file.
The point is not to know if strpos() is the faster (I think it is). But to know if, is it better to get all the content of the file and do strpos() ONLY ONCE, or to get the file line by line and do strpos() foreach line until I find my value (or until the end if the value is not found).