php验证手机号码(支持归属地查询及编码为UTF8)
(编辑:jimmy 日期: 2024/11/18 浏览:3 次 )
复制代码 代码如下:
<?php
// 手机号验证
function checkMobileValidity($mobilephone){
$exp = "/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{8}$|14[57]{1}[0-9]$/";
if(preg_match($exp,$mobilephone)){
return true;
}else{
return false;
}
}
// 手机号码归属地(返回: 如 广东移动)
function checkMobilePlace($mobilephone){
$url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobilephone."&t=".time();
$content = file_get_contents($url);
$p = substr($content, 56, 4);
$mo = substr($content, 81, 4);
return $str = conv2utf8($p).conv2utf8($mo);
}
// 转换字符串编码为 UTF8
function conv2utf8($text){
return mb_convert_encoding($text,'UTF-8','ASCII,GB2312,GB18030,GBK,UTF-8');
}
<?php
// 手机号验证
function checkMobileValidity($mobilephone){
$exp = "/^13[0-9]{1}[0-9]{8}$|15[012356789]{1}[0-9]{8}$|18[012356789]{1}[0-9]{8}$|14[57]{1}[0-9]$/";
if(preg_match($exp,$mobilephone)){
return true;
}else{
return false;
}
}
// 手机号码归属地(返回: 如 广东移动)
function checkMobilePlace($mobilephone){
$url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobilephone."&t=".time();
$content = file_get_contents($url);
$p = substr($content, 56, 4);
$mo = substr($content, 81, 4);
return $str = conv2utf8($p).conv2utf8($mo);
}
// 转换字符串编码为 UTF8
function conv2utf8($text){
return mb_convert_encoding($text,'UTF-8','ASCII,GB2312,GB18030,GBK,UTF-8');
}
下一篇:破解.net程序(dll文件)编译和反编译方法