How to obtain the IP address and region in php through Chianz.com, chianz.comip_PHP tutorial

WBOY
Release: 2016-07-13 10:09:40
Original
1409 people have browsed it

How to obtain the IP address and region in php through Chianz.com, chianz.comip

The example in this article describes how php obtains the IP address and region through Chianz.com. Share it with everyone for your reference. The specific analysis is as follows:

The result obtained by an IP is not very perfect. The reason is that the IP resolution of ip138 is not very detailed when dealing with foreign addresses, so I re-wrote a code using Chianz.com. The example code is as follows:

Copy code The code is as follows:










$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<$num;$i++){
$addrArray[0][$i] = preg_replace($pattern,"",$addrArray[0][$i]);
}
echo "
"; <br>
print_r($addrArray); <br>
echo "
";
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/942982.htmlTechArticleHow to obtain the IP address and region by php through Chianz.com, chianz.comip This article describes the example of php through Chianz. com method to obtain IP address and region. Share it with everyone for your reference. Specific points...
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 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!