Php: how to obtain IP addresses and regions through Chianz.com _ PHP Tutorial

Source: Internet
Author: User
Php uses Chianz.com to obtain the IP address and region. Php: how to obtain IP addresses and regions through Chianz.com this article mainly introduces how php obtains IP addresses and regions through Chianz.com. it is a very practical technique to parse IP addresses and regions, how to obtain the IP address and region through Chianz.com in php

This article mainly introduces how to obtain IP addresses and regions through Chianz.com in php. it is a very practical technique to parse IP addresses and regions. For more information, see

This example describes how php obtains IP addresses and regions through Chianz.com. Share it with you for your reference. The specific analysis is as follows:

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

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"

";   
print_r($addrArray);
echo "
";
?>

I hope this article will help you with php programming.

This article describes how to obtain IP addresses and regions through Chianz.com in php. it is a very practical technique to parse IP addresses and regions...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.