PHP 获取手机号运营商
2023-02-18 16:33:57 时间
1. 前言
公司有一个话费充值项目,需要获取手机号的运营商,进行执行不同的逻辑。
根据手机号的前三位就可以知道手机号的运营商
移动:134、135、136、137、138、139、150、151、157(TD)、158、159、187、188
联通:130、131、132、152、155、156、185、186
电信:133、153、180、189、(1349卫通)
2. PHP 获取手机号的运营商
这是我通过查找资料得到的一个函数,测试确实可用
/**
* 获取手机号运营商
*
* @param $mobile
* @return mobile|union|telcom|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'; // 移动
} else if (preg_match($isChinaUnion, $mobile)) {
return 'union'; // 联通
} else if (preg_match($isChinaTelcom, $mobile)) {
return 'telcom'; // 电信
} else {
return 'unknown'; // 未知
}
}
相关文章
- Power BI模拟麦肯锡多种正方形图表
- 如何用Power BI设计T恤
- Power BI 模拟麦肯锡华夫饼图
- Power BI 表格绝对值和百分比组合
- Power BI模拟小米运动APP三环效果
- Power BI 啤酒消费排行榜
- Power BI 模拟麦肯锡前后对比气泡图
- Excel 2013 Power Query 链接断开问题
- Power BI 排名、绝对值和增长率组合
- Power BI模拟麦肯锡哑铃图表现差异
- 【视频】Power BI 四象限划分
- Power BI 无限滚屏效果(适用于地图、卡片图滚动等)
- 我的Go+语言初体验——基于CentOS系统搭建Go+语言环境详细教程
- Power BI 条件格式红绿灯图标修改
- 我的Go+语言初体验——基于Windows系统创建Go+语言环境
- Power BI条件格式:含百分号的升降符
- Power BI 表格矩阵椭圆突出重点数据
- Parrot Linux安装教程
- Power BI如何插入本地视频?
- 第九届省赛蓝桥杯b组c++