最后如何用@ hotmail.com提取所有字符串。如果txt文件的名称是foo.txt
a@a.com jhgvhdhf bahau@gmail.com hdghfd G@g.com dxf@hotmail.com
sdfvdgfh
ghb@hotmail.com
答案 0 :(得分:0)
好吧,我当天没有做好事:
祝你好运。技术上,电子邮件地址可以包含空格,前提是它们被引用。我相信hotmail不允许这样做,所以你应该可以使用它:preg_match_all(/[^\s]+@hotmail\.com/, $string, $matches);
//replace $string with file_get_contents('path/to/foo.txt')
在您的代码段上,$matches
看起来像这样:
array ( 0 => array ( 0 => 'dxf@hotmail.com', 1 => 'ghb@hotmail.com', ), )
答案 1 :(得分:-1)
尝试使用此代码读取文件并解析:
if (($file = @file_get_contents('foo.txt'))
&& preg_match_all('/[^\s]+@hotmail.com/', $file, $matches)
) {
$result = $matches[0];
}
所以$ result将存储:
array(2) {
[0]=>
string(15) "dxf@hotmail.com"
[1]=>
string(15) "ghb@hotmail.com"
}