Home >Backend Development >PHP Tutorial >PHP combines regular expressions to batch capture email addresses in web pages and capture email addresses_PHP tutorial
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.
<?php $url='http://www.bkjia.com'; //要采集的网址 $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)); ?>
Method 2:
<?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)); ?>
The above is the entire content of this article, I hope you all like it.