我有一个文本文件,其中包含有关组织专家的一些成员信息。现在我只想从中提取电子邮件地址。
示例文件:
[email protected] /cdn-cgi/l/email-protection jhgvhdhf [email protected] /cdn-cgi/l/email-protection hdghfd [email protected] /cdn-cgi/l/email-protection
我怎样才能提取所有以结尾的字符串@hotmail.com
?如果文件名是 foo.txt...
将数据加载到字符串中(我正在使用$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');
EDIT:
对于 hotmail,您可以将模式更改为:
$pattern = '/[A-Z0-9._%+-][email protected] /cdn-cgi/l/email-protection/i';
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)