当前位置:首页 > PHP教程 > PHP常见问题

php结合正则批量抓取网页中邮箱地址

php如何抓取网页中邮箱地址,下面我就给大家分享一个用php抓取网页中电子邮箱的实例。

<?php
  $url='http://www.jb51.net'; //要采集的网址 
  $content=file_get_contents($url);
  //echo $content;
  function getemail($str) {
  //$pattern = "/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i";
  $pattern = "/([a-z0-9-_.]+@[a-z0-9]+.[a-z0-9-_.]+)/";
  preg_match_all($pattern,$str,$emailarr);
 
  return $emailarr[0];
  }
  print_r( getemail($content));
  ?>

方法2:

<?php 
$url='http://www.jb51.net'; //当页已留邮箱
$content=file_get_contents($url);             //获取页面内容
function getemail($str) {                 //匹配邮箱内容
$pattern = "/([a-z0-9-_.]+@[a-z0-9]+.[a-z0-9-_.]+)/"; 
preg_match_all($pattern,$str,$emailarr); 
return $emailarr[0]; 
} 
print_r( getemail($content)); 
?>

以上所述就是本文的全部内容了,希望大家能够喜欢。


【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!