比如说一个页面中有这样的内容风中有托玉镯的云,雾里看花。虚拟主机,很好、买主机联系:[email protected]
。有事联系 [email protected],[email protected].=======================================
请问要如何取得里面的所有邮箱地址并输出
。有事联系 [email protected],[email protected].=======================================
请问要如何取得里面的所有邮箱地址并输出
。有事联系 [email protected],[email protected].';$r = '#\w+@\w+\.(com|cn)#';
preg_match_all($r, $s, $a);
echo '<pre>';print_r($a[0]);exit;
/*
输出:Array
(
[0] => [email protected]
[1] => [email protected]
[2] => [email protected]
[3] => [email protected]
)
*/
...//假设包含邮箱字符串为$target
preg_match_all ("/\W+([-+.]\w+)*@\w+)*\.\w+([-.]\w+)*/",$target,$matches);//在$target中查找所有邮箱地址,保存到数组matches
for($i=0;$i<count($matches[0]);$i++)echo $matches[0][$i]."</br>"; //逐个输出matches中的邮箱地址
?>