How could I extract the all of strings with @hotmail.com,at the end. If the txt file's name is foo.txt
a@a.com jhgvhdhf bahau@gmail.com hdghfd G@g.com dxf@hotmail.com
sdfvdgfh
ghb@hotmail.com
How could I extract the all of strings with @hotmail.com,at the end. If the txt file's name is foo.txt
a@a.com jhgvhdhf bahau@gmail.com hdghfd G@g.com dxf@hotmail.com
sdfvdgfh
ghb@hotmail.com
Fine, I haven't done my good deed for the day:
Best of luck. Technically email addresses can contain spaces, provided they're quoted. I do believe hotmail doesn't allow that, so you should be able to use this:
preg_match_all(/[^\s]+@hotmail\.com/, $string, $matches);
//replace $string with file_get_contents('path/to/foo.txt')
On your snippet, $matches
then looks like this:
array ( 0 => array ( 0 => 'dxf@hotmail.com', 1 => 'ghb@hotmail.com', ), )
Try this code to read file and parse:
if (($file = @file_get_contents('foo.txt'))
&& preg_match_all('/[^\s]+@hotmail.com/', $file, $matches)
) {
$result = $matches[0];
}
So $result will store:
array(2) {
[0]=>
string(15) "dxf@hotmail.com"
[1]=>
string(15) "ghb@hotmail.com"
}