根据ip获取所在城市信息

来源:互联网 发布:自动化交易软件 编辑:程序博客网 时间:2024/06/05 06:56

最近在做一个关于根据ip返回不同的xml文件的项目,需要先根据ip去得到所在城市以及使用网络的信息。经过查找和自己实验,实现了这个目的。以下是自己实验成功的代码和运行结果。

function getAddr($ip){//$ip=mb_convert_encoding(file_get_contents("http://fw.qq.com/ipaddress"),"UTF-8", "GBK");$xml=iconv("GB2312","UTF-8",file_get_contents("http://int.dpool.sina.com.cn/iplookup/iplookup.php?ip=".$ip));$c=explode("\t",$xml);var_dump($c);return trim($c[7]);}

运行结果是

array(10) { [0]=> string(1) "1" [1]=> string(12) "202.108.20.0" [2]=> string(14) "202.108.23.255" [3]=> string(6) "中国" [4]=> string(6) "北京" [5]=> string(6) "北京" [6]=> string(0) "" [7]=> string(6) "联通" [8]=> string(6) "企业" [9]=> string(18) "百度公司联通" }

0 0
原创粉丝点击