龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > php编程 >

调用腾讯API显示你当前所在城市

时间:2014-07-22 14:50来源: 作者: 点击:
分享到:
a href=http://qita.in/bMv target=_blank rel=nofollowimg alt=填写您的邮件地址,订阅我们的精彩内容: src=http://static.oschina.net/uploads/img/201302/16195715_kPci.png //a h2 br / /h2
填写您的邮件地址,订阅我们的精彩内容:



<?php   
/*
调用腾讯的API接口http://blog.qita.in
返回结果 var IPData = new Array("114.238.55.147","","江苏省","淮安市");
0 为 IP地址
1 为 null
2 为 省份
3 为 城市
*/
function get_ip_place(){   
  $ip=file_get_contents("http://fw.qq.com/ipaddress");  
  $ip=str_replace('"',' ',$ip);   
  $ip2=explode("(",$ip);   
  $a=substr($ip2[1],0,-2);   
  $b=explode(",",$a);   
  return $b;   
}   
$ip=get_ip_place();   
print_r($ip);   
print_r($ip[0]); // 这个就是你当前外网IP地址
print_r($ip[2]); // 这个就是你所在的省份
print_r($ip[3]); //这个就是你所在的城市了
?>
精彩图集

赞助商链接