如何从字符串中提取所有电子邮件?
How to extract all emails from a string?
如何删除?
我有 html 个包含 300 000 行的文件
我想删除所有内容、所有标签、所有内容,但保留电子邮件。
文件中的示例:
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 个电子邮件地址。
试试这个例子:
<?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])));
?>
如何删除? 我有 html 个包含 300 000 行的文件 我想删除所有内容、所有标签、所有内容,但保留电子邮件。 文件中的示例:
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 个电子邮件地址。
试试这个例子:
<?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])));
?>