Filtering mails

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Filtering mails

Post by shaqa »

i have a text file with text on it and emails, how can i gather only emails from a text file and echo those.
email is in this mode:

Code: Select all

email: email@email.com
email.com can be: hotmail,yahoo,msn etc..

i was using but it doesnt work:

Code: Select all

$file = 'datafile.txt';
$lines = file($file);
 
foreach ($lines as $line)
{
$split = explode(' - ', $line);
$name = $split[0];
$id = $split[1]
 
if($split[0] == $name_I_am_searching_for)
{
//stop searching and show the result
}
}
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Filtering mails

Post by requinix »

Post an example of the text file, it'll help us.
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Filtering mails

Post by shaqa »

Search For: Sample, Sample, Sample
Sample: Sample



----------------------------------------------------------------------------------------------------


Start Search Number 1...

1 Sample Sample Sample Sample Sample Sample email: sSample09@gmail.com
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Filtering mails

Post by requinix »

So basically, whatever comes after an "email: "?

Code: Select all

$file = file_get_contents("datafile.txt");
preg_match_all('/(?<=email: )\S+/', $file, $matches);
print_r($matches[0]);
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Filtering mails

Post by shaqa »

im receiving lik :
Array ( [0] => Array ( [0] => samplemail9@gmail.com [1] => and so and so.
i want to show one email per line like:
sample@samp.com
sampel2.@gmpa.com etc,,

thank you
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Filtering mails

Post by requinix »

foreach or implode.

Come on, try to do some of this yourself.
Post Reply