This example describes the way PHP obtains IP addresses and regions via chianz.com. Share to everyone for your reference. The specific analysis is as follows:
The results of an IP acquisition is not perfect, the reason is because ip138 IP resolution of foreign address is not very detailed, so it has written a chianz.com code, the example code is as follows:
Copy Code code as follows:
<! DOCTYPE html>
<title></title>
<meta charset= "UTF-8"/>
<meta name= "Author" content= ""/>
<meta name= "keywords" content= ""/>
<meta name= "description" content= ""/>
<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>
I hope this article will help you with your PHP program design.