|
对php从字符串中提取email地址感兴趣的小伙伴,下面一起跟随脚本之家 jb51.cc的小编两巴掌来看看吧!
/**
* php从字符串中提取email地址
*
* @param
* @arrange 512-笔记网: www.jb51.cc
**/
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;
<a href="test3@example.org">foobar</a>
<test4@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));
/*** 来自脚本之家 jb51.cc(jb51.cc) ***/ (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|