Home > php教程 > php手册 > body text

php通过Chianz.com获取IP地址与地区的方法,chianz.comip

WBOY
Release: 2016-06-13 09:16:56
Original
932 people have browsed it

php通过Chianz.com获取IP地址与地区的方法,chianz.comip

本文实例讲述了php通过Chianz.com获取IP地址与地区的方法。分享给大家供大家参考。具体分析如下:

一个IP获取的结果不是很完善,究其原因是因为ip138的IP解析应对国外的地址时不是很详细,所以又重新写了个用Chianz.com的代码,实例代码如下:

复制代码 代码如下:

 
 

 
 
 
 
 
 

 
$ipAddr = "4.4.44.4"; 
$ipChinazAddr = "http://tool.chinaz.com/IP/?IP=".$ipAddr; 
$contents = file_get_contents($ipChinazAddr); 
$pattern = "/==>>.+
/"; 
$string = $contents; 
preg_match_all($pattern,$string,$addrArray); 
$num = count($addrArray[0]); 
$pattern = "/(==>>).+(==>>s)/"; 
for($i = 0;$i $addrArray[0][$i] = preg_replace($pattern,"",$addrArray[0][$i]); 

echo "
";  <br>
print_r($addrArray);  <br>
echo "
Copy after login
"; 
?> 
 

希望本文所述对大家的php程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!