采集邮箱的php代码(抓取网页中的邮箱地址)

(编辑:jimmy 日期: 2024/11/15 浏览:2)

复制代码 代码如下:
<?php
$url='https://www.jb51.net'; //这个网页里绝对含有邮件地址。
$content=file_get_contents($url);
//echo $content;
function getEmail($str) {
&nbsp;&nbsp;&nbsp;&nbsp;//$pattern = "/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i";
&nbsp;&nbsp;&nbsp;&nbsp;$pattern = "/([a-z0-9\-_\.]+@[a-z0-9]+\.[a-z0-9\-_\.]+)/";
&nbsp;&nbsp;&nbsp;&nbsp;preg_match_all($pattern,$str,$emailArr);
&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;return $emailArr[0];
}
print_r( getEmail($content));
?>