php 根据IP获取城市名称

180it 2019-12-12 PM 3007℃ 0条

//获取省份
function getArea($ip)
{

$ip = getIp();
$res1 = file_get_contents("http://pv.sohu.com/cityjson?ie=utf-8");
$str = cut('cname','};',$res1);
$str = str_replace('"',"",$str );
$str = str_replace(':',"",$str );
$str = str_replace("市","",$str );
$str = str_replace("北京市","",$str );

$str = str_replace("天津市","",$str );
$str = str_replace("上海市","",$str );
$str = str_replace("重庆市","",$str );
$str = str_replace("河北省","",$str );
$str = str_replace("山西省","",$str );
$str = str_replace("辽宁省","",$str );
$str = str_replace("吉林省","",$str );
$str = str_replace("黑龙江省","",$str );
$str = str_replace("江苏省","",$str );
$str = str_replace("浙江省","",$str );
$str = str_replace("安徽省","",$str );
$str = str_replace("福建省","",$str );
$str = str_replace("江西省","",$str );
$str = str_replace("山东省","",$str );
$str = str_replace("河南省","",$str );
$str = str_replace("湖北省","",$str );
$str = str_replace("湖南省","",$str );
$str = str_replace("广东省","",$str );
$str = str_replace("海南省","",$str );
$str = str_replace("四川省","",$str );
$str = str_replace("贵州省","",$str );
$str = str_replace("云南省","",$str );
$str = str_replace("陕西省","",$str );
$str = str_replace("甘肃省","",$str );
$str = str_replace("青海省","",$str );
$str = str_replace("台湾省","",$str );
$str = str_replace("内蒙古自治区","",$str );
$str = str_replace("广西壮族自治区","",$str );
$str = str_replace("西藏自治区","",$str );
$str = str_replace("宁夏回族自治区","",$str );
$str = str_replace("新疆维吾尔自治区","",$str );

if (!$str=='')
{
    return $str;
}else{
    return "";
}

}

支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

php 根据IP获取城市名称