PHP 字符串里提取邮箱

//字符串中提取邮箱
function getEmail($str) {
	$pattern = "/([a-z0-9]*[-_\.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[\.][a-z]{2,3}([\.][a-z]{2})?/i";
	preg_match_all($pattern,$str,$emailArr);
	return $emailArr;
}
$str = "大家好,欢迎 [email protected]";

print_r(getEmail($str));

   运行结果:

   Array ( [0] => Array ( [0] => [email protected] ) [1] => Array ( [0] => tjls ) [2] => Array ( [0] => 126 ) [3] => Array ( [0] => ) )

你可能感兴趣的:(PHP,字符串内提取邮箱)