本篇文章主要介绍php如何实现根据手机号判断运营商,感兴趣的朋友参考下,希望对大家有所帮助。
HTML页面
手机号归属 //修改为自己的路径
controller控制代码
/*
*@param string $phone 手机号字符串
*@return 0中国移动,1中国联通 2中国电信 3未知
*/
public function phone_check(){
if(IS_POST){
$phone = I('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)){
$this->ajaxReturn('中国移动'); //0
}else if(preg_match($isChinaUnion, $phone)){
$this->ajaxReturn('中国联通'); //1
}else if(preg_match($isChinaTelcom, $phone)){
$this->ajaxReturn('中国电信'); //2
}else{
$this->ajaxReturn('未知'); //3
}
}
$this->display();
}相关推荐:
立即学习“PHP免费学习笔记(深入)”;











