How could I extract the all of strings with @hotmail.com,at the end. If the txt file's name is foo.txt
[email protected] jhgvhdhf [email protected] hdghfd [email protected] [email protected]
sdfvdgfh
[email protected]
How could I extract the all of strings with @hotmail.com,at the end. If the txt file's name is foo.txt
[email protected] jhgvhdhf [email protected] hdghfd [email protected] [email protected]
sdfvdgfh
[email protected]
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 => '[email protected]', 1 => '[email protected]', ), )
Try this code to read file and parse:
if (($file = @file_get_contents('foo.txt'))
&& preg_match_all('/[^\s][email protected]/', $file, $matches)
) {
$result = $matches[0];
}
So $result will store:
array(2) {
[0]=>
string(15) "[email protected]"
[1]=>
string(15) "[email protected]"
}