Page 1 of 1

Filtering mails

Posted: Sun Mar 29, 2009 6:19 pm
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
}
}

Re: Filtering mails

Posted: Sun Mar 29, 2009 7:37 pm
by requinix
Post an example of the text file, it'll help us.

Re: Filtering mails

Posted: Mon Mar 30, 2009 5:32 pm
by shaqa
Search For: Sample, Sample, Sample
Sample: Sample



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


Start Search Number 1...

1 Sample Sample Sample Sample Sample Sample email: sSample09@gmail.com

Re: Filtering mails

Posted: Mon Mar 30, 2009 9:08 pm
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]);

Re: Filtering mails

Posted: Thu Apr 02, 2009 6:38 pm
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

Re: Filtering mails

Posted: Thu Apr 02, 2009 7:04 pm
by requinix
foreach or implode.

Come on, try to do some of this yourself.