时间:2021-07-01 10:21:17 帮助过:7人阅读
function GetTelphone($tel)
{
global $city,$dsql;
if(isset($tel)) $tel = GetAlabNum(trim($tel));//GetAlabNum函数用于替换全角数字,将可能存在的非法手机号码转换为数字;trim去除多余空格。
else return false;
if(strlen($tel) < 7) return false;
$tel = cn_substr($tel, 11);//先截取11个字符,防止是多个手机号码
//if(!is_numeric($tel)) return false;
if(cn_substr($tel, 1) == "0")//判断手机号码是否以0开头,这种情况可能会是座机号以0开头
{
if(cn_substr($tel, 2) == "01" || cn_substr($tel, 2) == "02") $tel = cn_substr($tel, 3);//3位区号
else $tel = cn_substr($tel, 4);
$row = $dsql->GetOne(" Select code,city as dd from `dede_tel` where code='$tel' group by code ");
}
else
{
$tel = cn_substr($tel, 7);
$row = $dsql->GetOne(" Select num,city as dd from `dede_tel` where num='$tel' ");
}
$city = $row['dd'];
if($city)
{
$city = str_replace("省", "-", $city);
$city = str_replace("市", "", $city);
$city = "
[".$city."]";
return $city;
}
}
api实现方法,这里不需要自己的数据库但有限制了
主要使用curl实现,需要开启php对curl的支持。
代码如下:
header(“Content-Type:text/html;charset=utf-8″);
if (isset($_GET['number'])) {
$url = ‘http://webservice.webxml.com.cn/WebServices/MobileCodeWS.asmx/getMobileCodeInfo';
$number = $_GET['number'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, “mobileCode={$number}&userId=”);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
$data = simplexml_load_string($data);
if (strpos($data, ‘http://')) {
echo ‘手机号码格式错误!';
} else {
echo $data;
}
}
?>
与php mysql手机号码归属地查询这个会慢很多,毕竟要通过第三方法数据。http://www.bkjia.com/PHPjc/325877.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/325877.htmlTechArticle首先我们介绍使用自己的数据库查询多个手机号码,那还是建议你拥有一个自己的的手机号码数据库。正常情况下,只是满足一般查询的话...