图灵编程

一个通过IP获取城市名的简单实现

2019-02-25  本文已影响1人  jack_jt_z

example:

ip地址:http://ip.taobao.com/service/getIpInfo.php?ip=’.$ip

使用方法:

<?php

$url =’http://ip.taobao.com/service/getIpInfo.php?ip=’ ;

$ip = ‘210.75.225.254’;

$path = $url . $ip;

$res = file_get_contents($path);

var_dump($res);

结果:

{
    “code”: 0,
    ”data”: {“
        ip”: ”210.75 .225 .254″,
        ”country”: ”中国”,
        ”area”: ””,
        ”region”: ”北京”,
        ”city”: ”北京”,
        ”county”: ”XX”,
        ”isp”: ”鹏博士”,
        ”country_id”: ”CN”,
        ”area_id”: ””,
        ”region_id”: ”110000″,
        ”city_id”: ”110100″,
        ”county_id”: ”xx”,
        ”isp_id”: ”1000143″
    }
}

原文地址:http://ip.taobao.com/instructions.html

上一篇 下一篇

猜你喜欢

热点阅读