PHP获取当前位置

版权声明:本文为Areom原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhanjianjiu/article/details/78522925
<?php
//{"code":0,"data":{"ip":"210.75.225.254","country":"\u4e2d\u56fd","area":"\u534e\u5317",
//"region":"\u5317\u4eac\u5e02","city":"\u5317\u4eac\u5e02","county":"","isp":"\u7535\u4fe1",
//"country_id":"86","area_id":"100000","region_id":"110000","city_id":"110000",
//"county_id":"-1","isp_id":"100017"}}
//其中code的值的含义为,0:成功,1:失败。

$ip = $_SERVER["REMOTE_ADDR"];
$url='http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
$code_json=file_get_contents($url);
$json = json_decode($code_json,true);
$shengfen=$json['data']['region'];//获取省份
$shi=$json['data']['city'];//获取市
preg_match_all("/[^市]+/u",$shi,$h);//获取市名字
//$str=str_replace("{shiming}",$h[0][0],$contents['title']);
?>

感谢第三方接口,淘宝IP库:http://ip.taobao.com/issue.php

猜你喜欢

转载自blog.csdn.net/zhanjianjiu/article/details/78522925