rence/php-locations

A pure PHP package for working with Countries, Cities, Areas, Languages and Currencies data

Maintainers

Package info

github.com/DavidAbalaku/php-locations

pkg:composer/rence/php-locations

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

v1.0.0 2025-11-11 08:40 UTC

This package is auto-updated.

Last update: 2026-03-11 09:29:37 UTC


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.