手机号的归属地查询
sanlanlan 2017-7-9 标签: PHP 浏览:1428 评论:0
要使用PHP判断手机号的归属地,方法有很多,有一种是利用第三方提供的api,例如
淘宝网API
API地址: http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443
参数:
tel:手机号码
返回:JSON
PHP调用淘宝API实例:
<?php
function get_mobile_area($mobile){
//根据淘宝的数据库调用返回值
$url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobile;
$content = file_get_contents($url); //get_mobile_area() 需要开启php的 allow url fopen 设置
$address = iconv("GBK", "UTF-8", substr($content, "56", "4") . " "
. substr($content, "81", "4"));//找出归属地并转换编码
return $address;
}
?>
淘宝网API
API地址: http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15850781443
参数:
tel:手机号码
返回:JSON
PHP调用淘宝API实例:
<?php
function get_mobile_area($mobile){
//根据淘宝的数据库调用返回值
$url = "http://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=".$mobile;
$content = file_get_contents($url); //get_mobile_area() 需要开启php的 allow url fopen 设置
$address = iconv("GBK", "UTF-8", substr($content, "56", "4") . " "
. substr($content, "81", "4"));//找出归属地并转换编码
return $address;
}
?>
发表评论: