【问题标题】:How to extract all emails from a string?如何从字符串中提取所有电子邮件?
【发布时间】:2015-03-11 03:44:41
【问题描述】:

如何去除? 我有 300 000 行的 html 文件 我想删除所有内容、所有标签、所有内容,但保留电子邮件。 文件中的示例:

ght="20"valign="top"bgcolor="#FFFFFF"><spanclass="style43style44">+995</strong>

<a href="mailto:mail@mail.com">mail@mail.com</a>

:fefw.gefew?chat">rewews</a>

在这个文件中是 1000 个电子邮件地址。

【问题讨论】:

  • 对我来说似乎是 blivit ;)
  • 这不是垃圾邮件@Dagon 一个只有 html 页面的旧网站。现在我用 PHP

标签: php html regex string email


【解决方案1】:

试试这个例子:

<?php

$content = 'ght="20"valign="top"bgcolor="#FFFFFF"><spanclass="style43style44">+995</strong>

<a href="mailto:mail@mail.com">mail@mail.com</a>
<a href="mailto:pol@hotmail.it">pol@hotmail.it</a>
john@doe.col-
:fefw.gefew?chat">rewews</a>';

$matches = array(); //create array
$pattern = "/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})/i";

preg_match_all($pattern, $content, $matches); 

print_r(array_values(array_unique($matches[0])));

?>

【讨论】:

  • @BeQaNikolashvili 不要忘记检查是否正确 ;-)
  • @BeQaNikolashvili 在答案左侧和选票底部的复选标记中,此时数字 1 在哪里
  • 需要 15 声望 ((
  • @BeQaNikolashvili 15 用于投票。但是您可以检查我的答案是否正确。请参阅页面stackoverflow.com/tour 带有绿色复选标记的第二张图片。 “提问者可以将一个答案标记为“已接受”。”
猜你喜欢
  • 2023-03-31
  • 2018-07-28
  • 1970-01-01
  • 2020-01-01
  • 2017-10-10
  • 2013-07-14
  • 1970-01-01
相关资源
最近更新 更多