PHPackages                             mohanedghawar/countries-info - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mohanedghawar/countries-info

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mohanedghawar/countries-info
============================

A comprehensive PHP library for accessing detailed country information, including regions, capitals, continents, and more.

00PHP

Since Dec 24Pushed 1y ago1 watchersCompare

[ Source](https://github.com/MohanedGhawar2019/countries-info-php)[ Packagist](https://packagist.org/packages/mohanedghawar/countries-info)[ RSS](/packages/mohanedghawar-countries-info/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

Countries Info PHP
==================

[](#countries-info-php)

A comprehensive PHP library for accessing detailed country information, including regions, cities, capitals, continents, and more.

Installation
------------

[](#installation)

```
composer require mohanedghawar/countries-info
```

Features
--------

[](#features)

- Complete country information (names, codes, capitals, etc.)
- Administrative regions for all countries (states, provinces, etc.)
- Detailed city data including:
    - City names and populations
    - Geographical coordinates
    - Hierarchical organization (Country -&gt; Region -&gt; Cities)
- Population and area data
- Continent information
- Easy-to-use API
- Regular updates

Usage
-----

[](#usage)

```
use MohanedGhawar\CountriesInfo\CountriesInfo;

$countriesInfo = new CountriesInfo();

// Get all countries
$countries = $countriesInfo->getAllCountries();

// Get country by code
$usa = $countriesInfo->getCountryByCode('USA');

// Get country by name
$france = $countriesInfo->getCountryByName('France');

// Get countries by continent
$europeanCountries = $countriesInfo->getCountriesByContinent('Europe');

// Search countries by name
$searchResults = $countriesInfo->searchByName('united');

// Get regions (states/provinces) for a country
$usStates = $countriesInfo->getCountryRegions('USA');

// Get cities in a specific region
$californiaCities = $countriesInfo->getCitiesByRegion('USA', 'California');

// Get all cities in a country
$allUsCities = $countriesInfo->getAllCitiesInCountry('USA');

// Get total number of cities in a country
$usCityCount = $countriesInfo->getCityCount('USA');

// Search for cities across all countries
$citiesNamedParis = $countriesInfo->searchCities('Paris');
```

API Reference
-------------

[](#api-reference)

### Methods

[](#methods)

#### Countries

[](#countries)

- `getAllCountries(): array`Returns an array of all country objects.
- `getCountryByCode(string $code): ?array`Returns a country object for the given 3-letter ISO code (e.g., 'USA', 'GBR').
- `getCountryByName(string $name): ?array`Returns a country object for the given country name.
- `getCountriesByContinent(string $continent): array`Returns an array of countries in the specified continent.
- `searchByName(string $query): array`Returns an array of countries whose names contain the search term.

#### Regions

[](#regions)

- `getCountryRegions(string $code): array`Returns an array of region names for the given country code.

#### Cities

[](#cities)

- `getCitiesByRegion(string $countryCode, string $regionName): array`Returns an array of city objects for the given country code and region name.
- `getAllCitiesInCountry(string $countryCode): array`Returns an array of city objects for the given country code.
- `getCityCount(string $countryCode): int`Returns the total number of cities in the given country code.
- `searchCities(string $name): array`Returns an array of city objects whose names contain the search term.

### Data Structures

[](#data-structures)

#### Country Object

[](#country-object)

```
[
    'name' => [
        'common' => 'United States',
        'official' => 'United States of America'
    ],
    'code' => 'USA',
    'capital' => 'Washington, D.C.',
    'continent' => 'North America',
    'population' => 331002651,
    'area_km2' => 9833517
]
```

#### City Object

[](#city-object)

```
[
    'name' => 'Los Angeles',
    'latitude' => '34.05223',
    'longitude' => '-118.24368',
    'population' => 3971883,
    'countryCode' => 'USA',  // Only included in searchCities results
    'regionName' => 'California'  // Only included in searchCities results
]
```

#### Regions Array

[](#regions-array)

```
// Example: $countriesInfo->getCountryRegions('USA')
[
    'Alabama',
    'Alaska',
    'Arizona',
    // ... all US states
    'Wisconsin',
    'Wyoming'
]
```

Data Coverage
-------------

[](#data-coverage)

- 250+ Countries
- 4,000+ Regions/States
- 150,000+ Cities worldwide

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a Pull Request.

License
-------

[](#license)

MIT License - see the [LICENSE](LICENSE) file for details.

Support
-------

[](#support)

If you encounter any issues or have questions, please file an issue on the [GitHub repository](https://github.com/MohanedGhawar2019/countries-info-php/issues).

###  Health Score

14

—

LowBetter than 2% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/457c309c4432d2ddc3d069f54f1a15210270ef42638c99357ba8602509693f05?d=identicon)[mohaned.ghawar](/maintainers/mohaned.ghawar)

---

Top Contributors

[![MohanedGhawar2019](https://avatars.githubusercontent.com/u/53141954?v=4)](https://github.com/MohanedGhawar2019 "MohanedGhawar2019 (3 commits)")

### Embed Badge

![Health badge](/badges/mohanedghawar-countries-info/health.svg)

```
[![Health](https://phpackages.com/badges/mohanedghawar-countries-info/health.svg)](https://phpackages.com/packages/mohanedghawar-countries-info)
```

###  Alternatives

[andrefigueira/blog-article-faker

Generate random blog article titles and content (including markdown) using faker

1415.0k](/packages/andrefigueira-blog-article-faker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
