PHP code example of atzcl / ip2region

1. Go to this page and download the library: Download atzcl/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/ */

    

atzcl / ip2region example snippets




ion = new Ip2Region\Ip2Region();

$ip = '101.105.35.57';
// 三种算法 binarySearch | btreeSearch | memorySearch
// 这里使用 b-tree 算法;作者原话:任何客户端b-tree都比binary算法快,当然Memory算法固然是最快的!
$ip_info = $ip2region->btreeSearch($ip);

echo '<pre>';
print_r($ip_info);

/***************************************************
    Array
    (
        [city_id] => 2163
        [region] => 中国|华南|广东省|深圳市|鹏博士
    )
 ***************************************************/