heres a very similar thing I wrote to add or remove email addresses to a text file for a mailing list, instead of deleteing tho, you want to do e preg_replace or whatever.
hope it points you in the right direction.
<?php
$email=stripslashes($HTTP_GET_VARS['email']);
$mailfile='mailing.txt';
$mailsize=filesize($mailfile);
if(!isset($unsub)){
$fd = fopen($mailfile, "r"

or die ('unable to open file');
$fcontents = file($mailfile);
$newmail=stripslashes(trim($email));
while(list($line_num,$line) = each ($fcontents)){
$line=trim($line);
if(preg_match("/\b$line\b/",$newmail)){
echo "$email is already listed<br>";
print("<a href='index.htm'> Back to form !</a>"

;
exit;
$count=1;
}
}
if($count == 0){
$fd = fopen($mailfile, "a"

;
$item=$email."\n";
fwrite($fd, $item);
fclose($fd);
echo "added $email to mailing list<br>";
print("<a href='index.htm'> Back to form !</a>"

;
}
}else{
$backup="$mailfile.bak";
$fp = fopen($backup, "w"

or die ('unable to open file');
$fcontents = file($mailfile);
$newmail=trim($email);
while(list($line_num,$line) = each ($fcontents)){
$line=trim($line);
if(!preg_match("/\b$line\b/",$newmail)){
fwrite($fp, $line."\n"

;
}else{
echo "Found and removed $newmail from the list";
}
}
fclose($fp);
copy($backup,$mailfile);
unlink($backup);
}
?> ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.