Home > php教程 > PHP源码 > 调用腾讯API显示你当前所在城市

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

PHP中文网
Release: 2016-05-25 17:10:29
Original
1434 people have browsed it

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

<?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(&#39;"&#39;,&#39; &#39;,$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]); //这个就是你所在的城市了
?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template