PDA

View Full Version : filter email addresses (in PHP)


edge
31st January 2008, 12:36
I have a list here with some email addresses that need to be "cleaned"
The list is in a text file, and looks like this

somename@domain1.com
someothername@domain2.com
anothername@domain1.com
andanothername@domain1.com
myname@domain2.com
notmyname@domain2.com
yetanothername@domain1.com
me@domain3.com
meme@domain3.com
mememe@domain2.com
* the list does have more email addresses, and this is only an example.

Now I need some PHP code to ONLY show all the email addresses from domain1.com (and if needed only from domain2.com or domain3.com ect...)

Someone here who can show me how this is done? (I guess it needs to make use of a wild card for the pre @ part)

Thank you

topdog
1st February 2008, 10:21
<?php
# andrew@topdog.za.net
#
$file = "path_to_file";
$domain = "domain1.com";

if(file_exists($file)){
$x = fopen($file,"r");
if($x){
while(!feof($x)){
$b = fgets($x, 4096);
if (eregi($domain, $b))
print "$b\n";

}
fclose($x);
}
}else{
print "File $file does not exist";
}
?>

edge
1st February 2008, 10:35
Thank you Andrew!

I'll be testing your code later today.