Let's say I have a big file. The file is a list of IPs each on a new line like this:
123.123.123.123
123.123.123.124
123.123.123.125
etc...
I could do it like this:
$file = file_get_contents($src);
if (substr_count($file,'myip'))
echo 'FOUND';
Or a similar way with array style:
$file = file($src,FILE_IGNORE_NEW_LINES);
if (in_array('myip',$file))
echo 'FOUND';
But I think there is a third alternative that could be faster.
Parsing the file line by line and of course stopping the reading if the string is found.
Something like this:
$file = fopen($src,'r');
while(!feof($file)) {
$ip = fgets($file);
if ($ip == $myIP) {
die('Found');
}
}
fclose($file);
My question is: do you think there are other better way?
And performance-wise which code do you think is faster?
Thanks a lot guys