一個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>
<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>";
print_r($addrArray);
echo "</pre>";
?>
</body>
</html>