function getoperator($mobile)
{
$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, $mobile)) {
return '1'; 移动
} else if (preg_match($isChinaUnion, $mobile)) {
return '2'; 联通
} else if (preg_match($isChinaTelcom, $mobile)) {
return '3'; 电信
} else {
return '0';
}
}
调用 例子:
$operator = $this->getoperator($tel);
这是一个用于检测手机号码所属运营商的PHP函数。它通过正则表达式匹配判断手机号码是否属于中国移动、中国联通或中国电信,返回相应的运营商标识。对于不匹配的号码,函数将返回0。
148

被折叠的 条评论
为什么被折叠?



