Hi folks,
I think there are possibly two errors in this script.
(1) $buffer = fgets($fd, 32000); should be
replaced with
$buffer .= fgets($fd, 32000);
add a dot, because otherwise $buffer is overwritten every execution of the loop.
The effect is that the file email.txt will be more or less overwritten with empty content.
(2) $str_replace("example@this.add","",$buffer);
I think, the goal was to do
$str_replace("example@this.add username","",$buffer);
Maybe you want to use ereg_replace() if there's a chance that there is more than one space ore a tab between 'add' and 'username'?
Using ereg_replace() can increase execution time a lot.
Another approach (I couldn't test it):
<?PHP
function checkMail((&$item,$key) {
if (strstr($item,"example@this.add username")) {
$item="";
}
}
$lineArr=file("email.txt");
array_walk($lineArr,'checkMail');
$fd=fopen("email.txt","w");
fputs($fd,implode("",$lineArr));
// maybe you need this, but I don't think so
//fputs($fd,implode("\n",$lineArr));
fclose($fd);
the file() function reads a file of size 1,5MB in about 2 sec. into an array on a P233MMX. I don't know how fast array_walk is ... just test it.
Greetings,
Thomas 🙂