冰豆网

分享网络精彩
bingdou.com.cn

php判断手机号运营商的方法

时间:2023-02-23加入收藏

php函数:

/**
 * # 判断手机号运营商
 * @param int $phone 手机号
 * 
 * @return string
 */
//feiniaomy.com
function phone_check($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}$/"; 
    if(preg_match($isChinaMobile, $phone)){
        return '中国移动';
    }else if(preg_match($isChinaUnion, $phone)){
        return '中国联通';
    }else if(preg_match($isChinaTelcom, $phone)){
        return '中国电信';
    }else{
        return '未知运营商';
    }
}

PS:运营商手机号码的信息收集自网络,可能会有一些不准备。

函数调用:

print_r(phone_check(13512345678));
//中国移动
print_r(phone_check(18612345678));
//中国联通

打 赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,你说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

TGA: php 技巧

分享到:


官方微信二维码冰豆网官方微信公众号