当前位置:网站首页>PHP get mobile number operator

PHP get mobile number operator

2022-06-26 04:35:00 On eel like water

1. Preface


The company has a charging project , The operator who needs to obtain the mobile phone number , Perform different logic .

According to the first three digits of the mobile phone number, you can know the operator of the mobile phone number

Move :134、135、136、137、138、139、150、151、157(TD)、158、159、187、188

Unicom :130、131、132、152、155、156、185、186

telecom :133、153、180、189、(1349 Weitong )

2. PHP The operator who gets the mobile phone number


This is a function I get by looking up data , Test is really available

/**
 *  Get the mobile number operator 
 *
 * @param  $mobile
 * @return mobile|union|telcom|unknown  Move | Unicom | telecom | Unknown 
 */
function getMobileServiceProvider($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 'mobile'; //  Move 
    } else if (preg_match($isChinaUnion, $mobile)) {
        return 'union'; //  Unicom 
    } else if (preg_match($isChinaTelcom, $mobile)) {
        return 'telcom'; //  telecom 
    } else {
        return 'unknown'; //  Unknown 
    }
}

原网站

版权声明
本文为[On eel like water]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202180527287013.html