Home >Backend Development >PHP Tutorial >PHP combines regular expressions to batch capture email addresses in web pages_PHP tutorial
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.
?
2 3
4 56 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));<🎜>
<🎜>?>
|
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));<🎜> <🎜>?> |