承接 lizhineng/region-china 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

lizhineng/region-china

最新稳定版本:v0.0.1

Composer 安装命令:

composer require lizhineng/region-china

包简介

China region library for PHP.

README 文档

README

MIT License

This library helps you manage regional data for mainland China, updated annually based on information from the Ministry of Civil Affairs of the People's Republic of China. The latest update was applied on April 25, 2025.

Installment

The library requires a minimum of PHP 8.4 and can be installed through Composer:

composer require lizhineng/region-china

Usage

The library includes built-in data sourced directly from the authority, so you don't need to maintain it yourself. You can find the update script in the scripts folder. First things first, let's initialize an instance of this helpful library.

use Zhineng\RegionChina\RegionManager;

$regions = RegionManager::createFromBuiltIn();

Resolve the region name from the code

Region codes are good for database persistence, but not very helpful for humans. If you have the region code, you can easily convert it back to the Chinese name.

$regions->getName($beijing = 110000); // 北京市

Retrieve provinces

When creating an interactive multi-level selector for choosing provinces, cities, and districts, it's helpful to first list all provinces in China, allowing you to display the corresponding cities and districts based on the user's selection.

$regions->getTopLevelNodes(); // [110000, 120000, 130000, ...]

Retrieve cities or districts

For example, if you want to list all cities in Guangdong Province or all districts in Guangzhou City, you only need a single API call to retrieve all sub-region codes for the specified area. You can then use these codes to obtain the corresponding names.

// Retrieve city codes for the Guangdong province
$regions->getNodes($guangdong = 440000);

// Retrieve district codes for the Guangzhou city
$regions->getNodes($guangzhou = 440100);

License

The library is released under the MIT License.

统计信息

  • 总下载量: 42
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: HTML

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-28