rence/php-locations 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

rence/php-locations

最新稳定版本:v1.0.0

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 data
  • cities.json - City data
  • areas.json - Area data
  • currencies.json - Currency data
  • languages.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.

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

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