PHP正则匹配联系方式手机号、QQ、微信、邮箱、固定电话
PHP正则匹配联系方式手机号、QQ、微信、邮箱、固定电话function contact($str=''){
if(!$str) die;
$phone = '/^1[345789]\d{9}$/ims';//手机号匹配
$qq = '/^\d{5,12}$/isu';
$email = '/^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*@([a-zA-Z0-9]+[-.])+([a-z]{2,5})$/ims';
$wchat = '/^[_a-zA-Z0-9]{5,19}+$/isu';
$tel = "/^([0-9]{3,4}-)?[0-9]{7,8}$/";
if(preg_match($phone,$str)){
echo '手机';
}else if(preg_match($qq,$str)){
echo 'QQ';
}else if(preg_match($email,$str)){
echo '邮箱';
}else if(preg_match($wchat,$str)){
echo '微信';
}else if(preg_match($tel,$str)){
echo '座机';
}else{
echo '未知';
}
}
$a = contact('010-7041210');
echo $a;