Home  >  Article  >  Backend Development  >  Share PHP tips: Get Chinese IP segment with PHP_PHP tutorial

Share PHP tips: Get Chinese IP segment with PHP_PHP tutorial

WBOY
WBOYOriginal
2016-07-15 13:32:391218browse

Everyone is learning

Go to this address to download the global IP segment http://ftp.apnic.net/apnic/dbase/data/country-ipv4.lst , inside cn is the Chinese IP range

Create a new php file called cnip.php, PHP obtains the specific code example of the Chinese IP range:

  1. < ?php
  2. $filefile = 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. > ,If you are in a window environment, change the "n" in fputs($handle, $ipLines[0]. '-'. $ipLines[2]. "n"); to "rn" Line break. http://www.bkjia.com/PHPjc/446128.html
www.bkjia.com


true


http: //www.bkjia.com/PHPjc/446128.html

TechArticle

Statement:
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