PHP code example of pangongzi / phone

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

    

pangongzi / phone example snippets



Pangongzi\Phone\PhoneLocation;

$phoneLocation = PhoneLocation::getInstance();

or

$dat = 'xxxx/phone.dat'; // 自定义dat文件
$phoneLocation = PhoneLocation::getInstance($dat);


$phone = '13800138000';
$result = $phoneLocation->find($phone);

if ($result !== null) {
    echo "省份: " . $result['province'] . PHP_EOL;
    echo "城市: " . $result['city'] . PHP_EOL;
    echo "邮政编码: " . $result['zip_code'] . PHP_EOL;
    echo "区号: " . $result['area_code'] . PHP_EOL;
    echo "运营商: " . $result['type_str'] . PHP_EOL;
} else {
    echo "未找到归属地信息" . PHP_EOL;
}


Array
(
    [province] => 浙江
    [city] => 嘉兴
    [zip_code] => 314000
    [area_code] => 0573
    [type] => 1
    [type_str] => 移动
    [phone] => 13800138000
    [info] => 13800138000|1|浙江|嘉兴|314000|0573
)