使用腾迅的api接口,php获取ip地址以及所在城市

    技术2025-12-19  9

    http://fw.qq.com/ipaddress返回类似:var IPData = new Array("221.4.154.138","","广西","南宁市");

    <?php    function get_ip_place(){    $ip=file_get_contents("http://fw.qq.com/ipaddress");    $ip=str_replace('"',' ',$ip);    $ip2=explode("(",$ip);    $a=substr($ip2[1],0,-2);    $b=explode(",",$a);    return $b;    }    $ip=get_ip_place();    print_r($ip);    ?>   <?php function get_ip_place(){ $ip=file_get_contents("http://fw.qq.com/ipaddress"); $ip=str_replace('"',' ',$ip); $ip2=explode("(",$ip); $a=substr($ip2[1],0,-2); $b=explode(",",$a); return $b; } $ip=get_ip_place(); print_r($ip); ?>

    代码测试地址:http://www.phpall.cn/forum/ci_data/ip_place.php

    该代码须联网使用的,它使用了腾迅的一个api,即http://fw.qq.com/ipaddress然后用php进行了一些简单的处理,使返回的结果用数组形式显示:即Array ( [0] => 61.164.140.51 [1] => [2] => 浙江省 [3] => 温州市 )这样大家就可以很方便的通过数组索引来调用ip地址和所在的省市了。希望对大家有用。

     

    最新回复(0)