Sometimes we have professional tools to collect content with email addresses on web pages on websites and extract the email addresses in the content. Let’s take a look at an example for reference if necessary.
[PHP]Code
The code is as follows
代码如下 |
复制代码 |
function extract_emails($str){
// This regular expression extracts all emails from a string:
$regexp = '/([a-z0-9_.-])+@(([a-z0-9-])+.)+([a-z0-9]{2,4})+/i';
preg_match_all($regexp, $str, $m);
return isset($m[0]) ? $m[0] : array();
}
$test_string = 'This is a test string...
test1@example.org
Test different formats:
test2@example.org;
foobar
strange formats:
test5@example.org
test6[at]example.org
test7@example.net.org.com
test8@ example.org
test9@!foo!.org
foobar ';
print_r(extract_emails($test_string));
|
|
Copy code |
|
function extract_emails($str){
// This regular expression extracts all emails from a string:
$regexp = '/([a-z0-9_.-])+@(([a-z0-9-])+.)+([a-z0-9]{2,4}) +/i';
preg_match_all($regexp, $str, $m);
return isset($m[0]) ? $m[0] : array();
}
$test_string = 'This is a test string...
test1@example.org
Test different formats:
test2@example.org;
strange formats:
test5@example.org
test6[at]example.org
test7@example.net.org.com
test8@example.org
test9@!foo!.org
foobar ';
print_r(extract_emails($test_string));
http://www.bkjia.com/PHPjc/631676.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631676.htmlTechArticleSometimes we have professional tools to collect content with email addresses on the web pages of the website, and add the email address in the content The address is extracted. Let’s look at an example below. Please refer to it if necessary...