rence/php-locations
Composer 安装命令:
composer require rence/php-locations
包简介
A pure PHP package for working with Countries, Cities, Areas, Languages and Currencies data
README 文档
README
A pure PHP package for working with Countries, Cities, Areas, Languages and Currencies data.
The package provides a comprehensive database with location data that can be used in any PHP application:
- 250 Countries
- 5038 Cities (States/Regions)
- 149350 Areas (Cities part of a State/Region)
- Currencies
- Languages
All data is stored in JSON files and can be accessed through simple PHP classes.
Requirements
- PHP 8.2 or higher
Installation
Install via Composer:
composer require rence/php-locations
Usage
Countries
use PhpLocations\Models\Country; // Get all countries $countries = Country::all(); // Get only active countries $activeCountries = Country::getActive(); // Find country by ID $country = Country::find(1); // Find country by ISO2 code $country = Country::findByIso2('US'); // Find country by ISO3 code $country = Country::findByIso3('USA'); // Access country properties echo $country->name; echo $country->iso2; echo $country->currency; // Get cities for a country $cities = $country->getCities();
Cities
use PhpLocations\Models\City; // Get all cities $cities = City::all(); // Get active cities $activeCities = City::getActive(); // Get cities by country ID $cities = City::getByCountryId(1); // Find city by ID $city = City::find(1); // Access city properties echo $city->name; echo $city->latitude; echo $city->longitude; // Get country for a city $country = $city->getCountry(); // Get areas for a city $areas = $city->getAreas();
Areas
use PhpLocations\Models\Area; // Get all areas $areas = Area::all(); // Get active areas $activeAreas = Area::getActive(); // Get areas by city ID $areas = Area::getByCityId(1); // Get areas by country ID $areas = Area::getByCountryId(1); // Find area by ID $area = Area::find(1); // Access area properties echo $area->name; // Get city for an area $city = $area->getCity(); // Get country for an area $country = $area->getCountry();
Currencies
use PhpLocations\Models\Currency; // Get all currencies $currencies = Currency::all(); // Get active currencies $activeCurrencies = Currency::getActive(); // Find currency by ID $currency = Currency::find(1); // Find currency by ISO code $currency = Currency::findByIso('USD'); // Access currency properties echo $currency->name; echo $currency->symbol; echo $currency->iso;
Languages
use PhpLocations\Models\Language; // Get all languages $languages = Language::all(); // Find language by ID $language = Language::find(1); // Find language by ISO code $language = Language::findByIso('en'); // Access language properties echo $language->name; echo $language->iso;
Data Structure
All data is stored in JSON files located in the database/data/ directory:
countries.json- Country datacities.json- City dataareas.json- Area datacurrencies.json- Currency datalanguages.json- Language data
You can also access the raw JSON data directly if needed.
License
This package is licensed under the MIT License. See the LICENSE file for more details.
rence/php-locations 适用场景与选型建议
rence/php-locations 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rence/php-locations 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rence/php-locations 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-11