-4

我有一个文本文件,其中包含一些有关组织专家的成员信息。现在我只想从中提取电子邮件地址。

示例文件:

a@a.com jhgvhdhf bahau@gmail.com hdghfd  G@g.com

我怎样才能提取所有以 结尾的字符串@hotmail.com?如果文件名是 foo.txt...

4

1 回答 1

0

将数据加载到字符串中(我正在使用$str它)并应用电子邮件正则表达式:

$pattern = '/[A-Z0-9._%+-]+@[^\.].*\.[a-z]{2,}/i';
if (preg_match($pattern, $str, $matches)){
    echo $matches[1];
}

正如 Guy 在下面评论的那样,您可以将文件加载到字符串中:

$str = file_get_contents('/path/to/file'); 

编辑:

对于 hotmail,您可以将模式更改为:

$pattern = '/[A-Z0-9._%+-]+@hotmail.com/i';
于 2013-07-09T07:45:45.687 回答