PHPackages                             datablock/countrycodes - 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. datablock/countrycodes

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

datablock/countrycodes
======================

Country codes and other info.

1.0.0(6y ago)08MITPHP

Since Dec 15Pushed 6y agoCompare

[ Source](https://github.com/datablock/CountryCodes)[ Packagist](https://packagist.org/packages/datablock/countrycodes)[ RSS](/packages/datablock-countrycodes/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (2)Used By (0)

DataBlock : Country Codes
=========================

[](#datablock--country-codes)

Install
-------

[](#install)

```
composer install datablock/countrycodes
```

Usage
-----

[](#usage)

### New instance

[](#new-instance)

```
new CountryCodes([?string $country=null]);
```

*Parameters :*

- `$country` ***string*** to define a specific country.

*Example :*

```
use \Datablock\CountryCodes\CountryCodes;
// ...
$countrycodes = new CountryCodes();
$countrycodes = new CountryCodes('FR');
```

### Set the country

[](#set-the-country)

Define or orverride the country definition :

```
$countrycodes->setCountry(string $country);
```

*Parameters :*

- `$country` ***string*** **(required)** to define a specific country.

```
use \Datablock\CountryCodes\CountryCodes;
// ...
$countrycodes = new CountryCodes();
// ...
$countrycodes->setCountry('FR');
```

### Database

[](#database)

Getting database as PHP array :

- If the `$country` is not defined, `getDatabase` return the full database.
- If the `$country` is defined, `getDatabase` return the database for the country.

```
$countrycodes->getDatabase([?string $country=null]);
```

- `getDatabase` return data as PHP array.
- `getJsonDatabase` return data as JSON file.

*Parameters :*

- `$country` ***string*** to define a specific country.

*Examples :*

- *Example 1 (Full database) :*

    ```
    use \Datablock\CountryCodes\CountryCodes;
    // ...
    $countrycodes = new CountryCodes();
    // ...
    $countrycodes->getDatabase();
    ```
- *Example 2 (Database for a specific country on instance) :*

    ```
    use \Datablock\CountryCodes\CountryCodes;
    // ...
    $countrycodes = new CountryCodes('FR');
    // ...
    $countrycodes->getDatabase();
    ```
- *Example 3 (Database for a specific country after instance) :*

    ```
    use \Datablock\CountryCodes\CountryCodes;
    // ...
    $countrycodes = new CountryCodes();
    // ...
    $countrycodes->setCountry('FR');
    // ...
    $countrycodes->getDatabase();
    ```
- *Example 4 (Database for a specific country only for the method) :*

    ```
    use \Datablock\CountryCodes\CountryCodes;
    // ...
    $countrycodes = new CountryCodes();
    // ...
    $countrycodes->getDatabase('FR');
    ```

### Get Country Name

[](#get-country-name)

- If the `$country` is not defined, `getCountryName` return the associative array of `['country_code'] => "Country name"`.
- If the `$country` is defined, `getCountryName` return the name of the country.

```
$countrycodes->getCountryName([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the code ISO Alpha 2

[](#get-the-code-iso-alpha-2)

- If the `$country` is not defined, `getIso2` return the associative array of `['country_code'] => "Country ISO 2"`.
- If the `$country` is defined, `getIso2` return the code iso alpha 2 of the country.

```
$countrycodes->getIso2([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the code ISO Alpha 3

[](#get-the-code-iso-alpha-3)

- If the `$country` is not defined, `getIso3` return the associative array of `['country_code'] => "Country ISO 3"`.
- If the `$country` is defined, `getIso3` return the code iso alpha 3 of the country.

```
$countrycodes->getIso3([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the TLD

[](#get-the-tld)

- If the `$country` is not defined, `getTld` return the associative array of `['country_code'] => "Country TLD"`.
- If the `$country` is defined, `getTld` return the TLD of the country.

```
$countrycodes->getTld([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the code FIPS

[](#get-the-code-fips)

- If the `$country` is not defined, `getFips` return the associative array of `['country_code'] => "Country FIPS"`.
- If the `$country` is defined, `getFips` return the code FIPS of the country.

```
$countrycodes->getFips([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the code ISO Numeric

[](#get-the-code-iso-numeric)

- If the `$country` is not defined, `getIsoNumeric` return the associative array of `['country_code'] => "Country ISO Numeric"`.
- If the `$country` is defined, `getIsoNumeric` return the code iso numeric of the country.

```
$countrycodes->getIsoNumeric([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the geoname ID

[](#get-the-geoname-id)

- If the `$country` is not defined, `getGeonameId` return the associative array of `['country_code'] => "Country Geoname ID"`.
- If the `$country` is defined, `getGeonameId` return the geoname ID of the country.

```
$countrycodes->getGeonameId([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the E164

[](#get-the-e164)

- If the `$country` is not defined, `getE164` return the associative array of `['country_code'] => "Country E164"`.
- If the `$country` is defined, `getE164` return the E164 of the country.

```
$countrycodes->getE164([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the PhoneCode

[](#get-the-phonecode)

- If the `$country` is not defined, `getPhoneCode` return the associative array of `['country_code'] => "Country PhoneCode"`.
- If the `$country` is defined, `getPhoneCode` return the PhoneCode of the country.

```
$countrycodes->getPhoneCode([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the Continent

[](#get-the-continent)

- If the `$country` is not defined, `getContinent` return the associative array of `['country_code'] => "Country Continent"`.
- If the `$country` is defined, `getContinent` return the Continent of the country.

```
$countrycodes->getContinent([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the Capital

[](#get-the-capital)

- If the `$country` is not defined, `getCapital` return the associative array of `['country_code'] => "Country Capital"`.
- If the `$country` is defined, `getCapital` return the Capital of the country.

```
$countrycodes->getCapital([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the Timezone

[](#get-the-timezone)

- If the `$country` is not defined, `getTimezone` return the associative array of `['country_code'] => "Country Timezone"`.
- If the `$country` is defined, `getTimezone` return the Timezone of the country.

```
$countrycodes->getTimezone([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the Currency

[](#get-the-currency)

- If the `$country` is not defined, `getCurrency` return the associative array of `['country_code'] => "Country Currency"`.
- If the `$country` is defined, `getCurrency` return the Currency of the country.

```
$countrycodes->getCurrency([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the LanguageCodes

[](#get-the-languagecodes)

- If the `$country` is not defined, `getLanguageCodes` return the associative array of `['country_code'] => "Country LanguageCodes"`.
- If the `$country` is defined, `getCurrency` return the LanguageCodes of the country.

```
$countrycodes->getLanguageCodes([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the Languages

[](#get-the-languages)

- If the `$country` is not defined, `getLanguages` return the associative array of `['country_code'] => "Country Languages"`.
- If the `$country` is defined, `getLanguages` return the Languages of the country.

```
$countrycodes->getLanguages([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

### Get the Area

[](#get-the-area)

- If the `$country` is not defined, `getArea` return the associative array of `['country_code'] => "Country Area"`.
- If the `$country` is defined, `getArea` return the Area of the country.

```
$countrycodes->getArea([?string $country=null]);
```

*Parameters* &amp; *Examples :* same as [`getDatabase`](#database)

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

2344d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/57695388?v=4)[DataBlock](/maintainers/datablock)[@datablock](https://github.com/datablock)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/datablock-countrycodes/health.svg)

```
[![Health](https://phpackages.com/badges/datablock-countrycodes/health.svg)](https://phpackages.com/packages/datablock-countrycodes)
```

###  Alternatives

[ejsmont-artur/php-circuit-breaker

PHP Circuit Breaker component

169964.9k4](/packages/ejsmont-artur-php-circuit-breaker)[politriukas/avataaars

PHP SVG avatar generator based on https://github.com/fangpenlin/avataaars-generator

112.0k](/packages/politriukas-avataaars)

PHPackages © 2026

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