I would like to understand how to use the buffer of a read file.
Assuming we have a large file with a list of letters per line (classic separator \n)
Now, we want to compare each row with each table entry in our database as a type check line_of_file == table_row.
This is a simple task if you have a normal file, otherwise, if you have a huge file, the server usually stops the operation after a few minutes.
so what's the best way to do this stuff with a file buffer?
that I still have something like this:
$buffer = file_get_contents('file.txt');
while($row = mysql_fetch_array($result)) {
if ( preg_match('/'.$email.'/im',$buffer)) {
echo $row_val;
}
}
$buffer = file_get_contents('file.txt');
$lines = preg_split('/\n/',$buffer);
//or $lines = explode('\n',$buffer);
while($row = mysql_fetch_array($result)) {
if ( in_array($email,$lines)) {
echo $row_val;
}
}
source
share