PHP code example of crgao / ip2region
1. Go to this page and download the library: Download crgao/ip2region library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
crgao / ip2region example snippets
composer
$ip2region = new Ip2Region();
$ip = '101.96.11.3';
#可拿來驗證IP格式
$ip = Ip2Region::safeIp2long($ip);
#btreeSearch
$info = $ip2region->btreeSearch($ip);
print_r($info);
#binarySearch
$info = $ip2region->binarySearch($ip);
print_r($info);
#memorySearch
$info = $ip2region->memorySearch($ip);
print_r($info);