https://github.com/dakalab/division-code
Administrative division codes of China (http://www.mca.gov.cn/article/sj/xzqh/)
https://github.com/dakalab/division-code
city county division province
Last synced: about 1 month ago
JSON representation
Administrative division codes of China (http://www.mca.gov.cn/article/sj/xzqh/)
- Host: GitHub
- URL: https://github.com/dakalab/division-code
- Owner: dakalab
- License: mit
- Created: 2018-11-21T10:38:31.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-05T09:03:06.000Z (over 5 years ago)
- Last Synced: 2025-08-29T11:23:22.796Z (10 months ago)
- Topics: city, county, division, province
- Language: PHP
- Homepage:
- Size: 676 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# division code
[](https://travis-ci.org/dakalab/division-code)
[](https://codecov.io/gh/dakalab/division-code)
[](https://packagist.org/packages/dakalab/division-code)
[](https://packagist.org/packages/dakalab/division-code)
[](https://packagist.org/packages/dakalab/division-code)
Administrative division codes of China (http://www.mca.gov.cn/article/sj/xzqh/)
This library has two ways of storage: php array file and SQLite3 database, see the benchmark below. The library will automatically detect if your php support SQLite3, if yes then it will use SQLite3, otherwise it will fall back to use php array.
You can also use function `useSQLite($v = true)` to turn on or turn off using SQLite.
## Install
```
composer require dakalab/division-code
```
## Usage
```
use Dakalab\DivisionCode\DivisionCode;
$divisionCode = new DivisionCode;
$res = $divisionCode->get('110000'); // 北京市
// Get all the provinces
$provinces = $divisionCode->getAllProvinces();
print_r($provinces);
// Get all the cities in the specified province
$province = '110000';
$cities = $divisionCode->getCitiesInProvince($province);
print_r($cities);
// Get all the counties in the specified city
$city = '445200';
$counties = $divisionCode->getCountiesInCity($city);
print_r($counties);
// Get all the cities in the specified province by the province name
$province = '广东省';
$cities = $divisionCode->getCitiesByProvinceName($province);
print_r($cities);
```
## Upgrade
If you want to upgrade the division codes by yourself, you can simply run the `Upgrader`
```
use Dakalab\DivisionCode\Upgrader;
$upgrader = new Upgrader;
$upgrader->upgrade();
```
## Benchmark
For a loop of 1000000 calls ran on a MacBook Pro 2.9 GHz Intel Core i5, 8GB 1867 MHz DDR3:
**Use sqlite3**
Time cost: 23.28 s, Memory cost: 15.85 kb
**Use php array**
Time cost: 0.47 s, Memory cost: 287.45 kb
**Conclusion**
SQLite3 uses less memory usage but slower, built-in php array is much faster but costs much more memory.