php 判断手机号运营商

/*
     移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
     联通:130、131、132、152、155、156、185、186
     电信:133、153、180、189、(1349卫通)
     */
    /**
     *   手机服务商函数 getphonetype
     *@author by @tianxiao
     *@param  string  $phone   手机号字符串
     *@return  unsignedint   0中国移动,1中国联通  2中国电信  3未知
     **/
    function getphonetype($phone){
        $phone = trim($phone);
        $isChinaMobile = "/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[2-478])\d{8}$/"; //移动方面最新答复
        $isChinaUnion = "/^(?:13[0-2]|145|15[56]|176|18[56])\d{8}$/"; //向联通微博确认并未回复
        $isChinaTelcom = "/^(?:133|153|177|173|18[019])\d{8}$/"; //1349号段 电信方面没给出答复,视作不存在
        // $isOtherTelphone = "/^170([059])\\d{7}$/";//其他运营商
        if(preg_match($isChinaMobile, $phone)){
            return 0;
        }elseif(preg_match($isChinaUnion, $phone)){
            return 1;
        }elseif(preg_match($isChinaTelcom, $phone)){
            return 2;
        }else{
            return 3;
        }
    }

 

/* 移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188 联通:130、131、132、152、155、156、185、186 电信:133、153、180、189、(1349卫通) *//** *   手机服务商函数 getphonetype *@author by @tianxiao *@param  string  $phone   手机号字符串 *@return  unsignedint   0中国移动,1中国联通  2中国电信  3未知 **/function getphonetype($phone){    $phone = trim($phone);    $isChinaMobile = "/^134[0-8]\d{7}$|^(?:13[5-9]|147|15[0-27-9]|178|18[2-478])\d{8}$/"; //移动方面最新答复    $isChinaUnion = "/^(?:13[0-2]|145|15[56]|176|18[56])\d{8}$/"; //向联通微博确认并未回复    $isChinaTelcom = "/^(?:133|153|177|173|18[019])\d{8}$/"; //1349号段 电信方面没给出答复,视作不存在    // $isOtherTelphone = "/^170([059])\\d{7}$/";//其他运营商    if(preg_match($isChinaMobile, $phone)){        return 0;    }elseif(preg_match($isChinaUnion, $phone)){        return 1;    }elseif(preg_match($isChinaTelcom, $phone)){        return 2;    }else{        return 3;    }}

转载于:https://www.cnblogs.com/zhangzhijian/p/7943088.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值