PHP獲取ip對應地區(qū)和使用網(wǎng)絡(luò)類型的方法

字號:


    這篇文章主要介紹了PHP獲取ip對應地區(qū)和使用網(wǎng)絡(luò)類型的方法,實例分析了php通過調(diào)用ip138數(shù)據(jù)庫獲取IP及網(wǎng)絡(luò)類型的技巧,需要的朋友可以參考下
    本文實例講述了PHP獲取ip對應地區(qū)和使用網(wǎng)絡(luò)類型的方法。分享給大家供大家參考。具體分析如下:
    這里測試的時候因為ip168網(wǎng)站禁止,所以試著在原有代碼上修改為ip138數(shù)據(jù)庫的數(shù)據(jù)調(diào)用,代碼如下:
    <?php
    //原程序有問題,現(xiàn)修改為ip138數(shù)據(jù)庫
    /**
    * 獲取IP地區(qū)
    * Enter description here ...
    * @param unknown_type $ip
    */
    function GetArea($ip){
    $url = "";
    $contents = file_get_contents($url);
    preg_match_all('|<li>本站主數(shù)據(jù):.*</li>|',$contents,$rsR);
    $rsR[0][0] = str_replace("<li>本站主數(shù)據(jù):", "", $rsR[0][0]);
    $pos = strpos($rsR[0][0],'</li>');
    $Area = substr_replace($rsR[0][0],'',$pos);
    return $Area;
    }
    header('Content-type:text/html;Charset=gb2312');
    $area = GetArea('218.242.232.194');
    print_r($area);
    ?>
    希望本文所述對大家的php程序設(shè)計有所幫助。