温馨提示  2024年 6月我们已经停止开发者板块文章内容更新,谢谢来访。存档数据
知识 2023-08-25 49 次阅读

php 怎么实现判断联通还是电信

   

php实现判断联通还是电信的方法 1. 创建一个html页面并通过js代码验证手机号码是否正确; 2. 通过php代码“public function phone,check(){...}”判断号码是联通还是电信即可。

本文操作环境windows7系统,php7.4版,dell g3电脑。

php 怎么实现判断联通还是电信?

php判断手机号运营商(详细介绍附代码)

道理很简单,知道手机号规则 进行正则判断就可以

移动13 4. 13 5. 13 6. 13 7. 13 8. 13 9. 15 0. 15 1. 157(td)、15 8. 15 9. 18 7. 188

联通13 0. 13 1. 13 2. 15 2. 15 5. 15 6. 18 5. 186

电信13 3. 15 3. 18 0. 18 9. (1349卫通)

html页面

<!doctype html><html><head> <title>手机号归属</title></head><body> <input type=text onblur=mobile,check($(this).val()) ></body></html><script type=text/javascript src=,,root,,/public/admin/lib/jquery/1.9.1/jquery.min.js></script>  //修改为自己的路径<script> /* 移动13 4. 13 5. 13 6. 13 7. 13 8. 13 9. 15 0. 15 1. 157(td)、15 8. 15 9. 18 7. 188 联通13 0. 13 1. 13 2. 15 2. 15 5. 15 6. 18 5. 186 电信13 3. 15 3. 18 0. 18 9. (1349卫通) */ var phone = ''; function mobile,check(phone){ if(phone.length !== 11){ alert('未检测到正确的手机号码'); return false; } $.ajax({ url:,,controller,,/phone,check, async:false, datatype:'json', type:'post', data:{phone:phone}, success:function(msg){ alert(msg); } }); }</script>

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视频教程》