Home >Backend Development >PHP Tutorial >PHP combines regular expressions to batch capture email addresses in web pages and capture email addresses_PHP tutorial

PHP combines regular expressions to batch capture email addresses in web pages and capture email addresses_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:53:17962browse

php combines regular expressions to batch capture email addresses in web pages, capture email addresses

How to capture email addresses in web pages with php, below I will share with you how to capture email addresses in php An example of an email address on a web page.

<&#63;php
  $url='http://www.bkjia.com'; //要采集的网址 
  $content=file_get_contents($url);
  //echo $content;
  function getEmail($str) {
  //$pattern = "/([a-z0-9]*[-_\.]&#63;[a-z0-9]+)*@([a-z0-9]*[-_]&#63;[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})&#63;/i";
  $pattern = "/([a-z0-9\-_\.]+@[a-z0-9]+\.[a-z0-9\-_\.]+)/";
  preg_match_all($pattern,$str,$emailArr);
 
  return $emailArr[0];
  }
  print_r( getEmail($content));
  &#63;>

Method 2:

<&#63;php 
$url='http://www.bkjia.com'; //当页已留邮箱
$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)); 
&#63;>

The above is the entire content of this article, I hope you all like it.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1001855.htmlTechArticlephp combines regex to batch capture email addresses in web pages, capture email addresses, how to capture email addresses in web pages with php, Now I will share with you an example of using php to capture emails from web pages...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn