這篇文章主要介紹了PHP獲取ip對(duì)應(yīng)地區(qū)和使用網(wǎng)絡(luò)類(lèi)型的方法,實(shí)例分析了php通過(guò)調(diào)用ip138數(shù)據(jù)庫(kù)獲取IP及網(wǎng)絡(luò)類(lèi)型的技巧,需要的朋友可以參考下
本文實(shí)例講述了PHP獲取ip對(duì)應(yīng)地區(qū)和使用網(wǎng)絡(luò)類(lèi)型的方法。分享給大家供大家參考。具體分析如下:
這里測(cè)試的時(shí)候因?yàn)閕p168網(wǎng)站禁止,所以試著在原有代碼上修改為ip138數(shù)據(jù)庫(kù)的數(shù)據(jù)調(diào)用,代碼如下:
<?php
//原程序有問(wèn)題,現(xiàn)修改為ip138數(shù)據(jù)庫(kù)
/**
* 獲取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);
?>
希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。
更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄