I have some code that takes from a txt file a list of emails and inserts them into a database, making sure not to add the email if it's already in said database. What I'm trying to do now is filter emails as they are read from the txt file and NOT insert them if they are an exact or partial match to any strings within the $filter array. In other words, if the email has 'gmail', '.ru' or 'exec' anywhere within the email address, I don't want it added.
Any help to stop the bleeding from me pounding my head against a wall would be great!
The code:
$TheFile = "emails.txt";
$handle = fopen($TheFile, 'r');
$good_count = 0;
$bad_count = 0;
$filter= array("gmail",".ru","exec");
while (!feof($handle))
{
$Data = fgets($handle, 1024);
$output = explode (",",$Data);
$exist = mysql_query("SELECT * FROM table WHERE email='$output[0]'");
if (mysql_num_rows ($exist) == 0) {
$email = strtolower($output[0]);
$sql = "INSERT INTO table SET email='$email'";
mysql_query($sql);
$good_count = $good_count + 1;
}
else {
$bad_count = $bad_count + 1;
}
}