PHP code example of simplephp / ip2region

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

    

simplephp / 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
//     [country] => 中国
//     [regionCode] => 0
//     [province] => 江苏省
//     [city] => 南京市
//     [operators] => 移动 
// )