Home >php教程 >php手册 >php获取Chianz.com IP地址与地区方法

php获取Chianz.com IP地址与地区方法

WBOY
WBOYOriginal
2016-05-25 16:57:561199browse

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

<!DOCTYPE html>  
	<html lang="en">  
	<head>  
	<title></title>  
	<meta charset="UTF-8" />  
	<meta name="author" content="" />  
	<meta name="keywords" content="" />  
	<meta name="description" content="" />  
	</head> //开源代码phprm.com 
	<body>  
	<?php 
	$ipAddr = "4.4.44.4";  
	$ipChinazAddr = "http://tool.chinaz.com/IP/?IP=".$ipAddr;  
	$contents = file_get_contents($ipChinazAddr);  
	$pattern = "/==>>.+</strong><br />/";  
	$string = $contents;  
	preg_match_all($pattern,$string,$addrArray);  
	$num = count($addrArray[0]);  
	$pattern = "/(==>>).+(==>>s)/";  
	for($i = 0;$i<$num;$i++){  
	$addrArray[0][$i] = preg_replace($pattern,"",$addrArray[0][$i]);  
	}  
	echo "<pre class="brush:php;toolbar:false">";  
	print_r($addrArray);  
	echo "
";     
Statement:
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