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

PHP combines regular expressions to batch capture email addresses in web pages_PHP tutorial

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

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

How to capture email addresses in web pages with php. Now I will share with you a method of using php to capture email addresses in web pages. Example.

 ?

1

2

3

4

5

6

7

8

9

10

11

12

13

$url='http://www.bkjia.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));

?>

1

2

3

1

2

3

4

5

6

7

8

9

10

$url='http://www.jbkjia.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));

?>

4

5

6

8 9 10 11 12
13
<🎜>$url='http://www.bkjia.net'; //The URL to be collected<🎜> <🎜>$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:  ?
1 2 3 4 5 6 7 8 9 10 <🎜>$url='http://www.jbkjia.net'; //An email address has been left on this page<🎜> <🎜>$content=file_get_contents($url); //Get page content<🎜> <🎜>function getEmail($str) { //Match email content<🎜> <🎜>$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. http://www.bkjia.com/PHPjc/1002347.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1002347.htmlTechArticlephp combines regular expressions to batch capture email addresses in web pages. How to capture email addresses in web pages with php? I will tell you below Share an example of using php to capture emails from web pages. ? 1 2 3 4 5 6...
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