PHP正则匹配手机号、微信、QQ、座机固话

PHP正则匹配手机号、微信、QQ、座机固话,上代码,由于时间仓促,手机号需要优化,还请各位见谅

$str = '15040481203';

function number($str){
    $str = strip_tags(trim($str));

    // 过滤网址字符串
    $url = preg_match("/^http(s)?:\\/\\/.+/",$str);

    if($str&&!$url){
        $phReg = "/[1][34578]\d{9}+/u";
        if(preg_match_all($phReg, $str, $matches)){
            return array('type'=>'手机','number'=>implode('', $matches[0]));
        }
        $wxReg = '/[a-zA-Z][a-zA-Z0-9_-]{5,19}+/u';
        if(preg_match_all($wxReg, $str, $matches)){
            return array('type'=>'微信','number'=>implode('', $matches[0]));
        }
        $emailReg = "/[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,})/u";
        if(preg_match($emailReg, $str, $matches)){
            return array('type'=>'邮箱','number'=>$matches[0]);
        }
        $qqReg = "/\d{5,12}/isu";
        if(preg_match($qqReg, $str, $matches)){
            return array('type'=>'QQ','number'=>$matches[0]);
        }
        $telReg = "/\d{5,12}/isu";
        if(preg_match($telReg, $str, $matches)){
            return array('type'=>'座机','number'=>$matches[0]);
        }
    }
}
$m = number($str);
var_dump($m);

 

你可能感兴趣的:(PHP,php)