PHP获取ip对应地区

根据ip获取对应的地区,使用ip168的数据库,适合初学者

  /**
  * 获取IP地区
  * Enter description here ...
  * @param unknown_type $ip
  */
function GetArea($ip){

    $url = "http://ip168.com/ip/?ip=".$ip;
    $contents = file_get_contents($url);
//    preg_match_all('/<h3[\s\S]*?(<a[\s\S]*?<\/h3>)/',$contents,$rs);
    preg_match_all('|<div>本站主数据:.*</div>|',$contents,$rsR);
    $rsR[0][0] = str_replace("<div>本站主数据:", "", $rsR[0][0]);
    $rsR[0][0] = str_replace("</div>", "", $rsR[0][0]);
    return $rsR[0][0];
}

作者: 张沫   发布时间: 2011-09-05

无兄弟不编程

作者: kyubii   发布时间: 2011-09-05