Share PHP tips php get China IP segment _php Tutorial

Source: Internet
Author: User
Everybody's learning.

Go to this address download global IP segment Http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst, CN is China IP segment range

Create a new PHP file called cnip.php,php get Chinese IP Segment specific code example:

  1. < ? PHP
  2. $ file file = File ('./country-ipv4.lst ');
  3. $ Handle = fopen ('./cnip.txt ', ' a ');
  4. if ($handle) {
  5. foreach ($file as $key => $val) {
  6. if (Strpos ($val, ' # ')!== 0) {
  7. $ Iplines = Explode (', $val);
  8. if ($ipLines [6] = = ' cn ') {
  9. Fputs ($handle, $ipLines [0]. '-'. $ipLines [2]. "N");
  10. }
  11. }
  12. }
  13. }
  14. ?>

Open cnip.txt China's IP segment range is completed by PHP to get the Chinese IP segment,
If it is in the window environment, the fputs ($handle, $ipLines [0]. '-'. $ipLines [2]. "N"); "N" in the Change to "RN" to break the line.


http://www.bkjia.com/PHPjc/446128.html www.bkjia.com true http://www.bkjia.com/PHPjc/446128.html techarticle Everyone is learning to go to this address to download the global IP segment http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst, inside CN is the IP segment range of China Create a new PHP file called cnip.php,php get in ...

  • 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.