php ip138获取,php通过调用ip138数据库获取IP及网络类型
這篇文章主要介紹了PHP獲取ip對應(yīng)地區(qū)和使用網(wǎng)絡(luò)類型的方法,實(shí)例分析了php通過調(diào)用ip138數(shù)據(jù)庫獲取IP及網(wǎng)絡(luò)類型的技巧,需要的朋友可以參考下
本文實(shí)例講述了PHP獲取ip對應(yīng)地區(qū)和使用網(wǎng)絡(luò)類型的方法。具體分析如下:
這里測試的時(shí)候因?yàn)閕p168網(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 = "http://www.ip138.com/ips8.asp?ip=".$ip."&action=2";
$contents = file_get_contents($url);
preg_match_all('|
本站主數(shù)據(jù):.*|',$contents,$rsR);$rsR[0][0] = str_replace("
本站主數(shù)據(jù):", "", $rsR[0][0]);$pos = strpos($rsR[0][0],'
');$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);
?>
總結(jié):以上就是本篇文的全部內(nèi)容,希望能對大家的學(xué)習(xí)有所幫助。
相關(guān)推薦:
php基于curl實(shí)現(xiàn)多線程抓取
php創(chuàng)建鏈表及針對鏈表節(jié)點(diǎn)的增加、刪除、更新與遍歷
php數(shù)字金額轉(zhuǎn)換成中文大寫金額的函數(shù)
總結(jié)
以上是生活随笔為你收集整理的php ip138获取,php通过调用ip138数据库获取IP及网络类型的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《网页设计与制作》的编写过程1
- 下一篇: PHP使用正则表达式验证电话号码(手机和