php根据ip获取城市地址

 代码相当简单,主要是利用了有道的一个地址查询接口

 

function get_address_from_ip($ip)

{

$url='http://www.youdao.com/smartresult-xml/search.s?type=ip&q=';

$xml=file_get_contents($url.$ip);

$data=simplexml_load_string($xml);

return $data->product->location;

}

以下一张图片可以显示当前浏览这个网页的童鞋的IP,大家可以拿回去放在QQ空间或者其他的论坛等地方都可以的!



文章来自: 本站原创
Tags:
评论: 0 | 查看次数: 6114