PHP code example of firstphp / ip2region

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

    

firstphp / ip2region example snippets


use Hyperf\Di\Annotation\Inject;

......

/**
 * @Inject()
 * @var \Firstphp\Ip2region\Ip2region
 */
protected $ip2region;

......

$res = $this->ip2region->binarySearch($ip = "223.104.148.63");

var_dump($res);


// Array
// (
//     [city_id] => 1015
//     [region] => 中国|0|江苏省|南京市|移动
// )