An open API service indexing awesome lists of open source software.

https://github.com/hollodotme/iso-country-codes

A value object collection representing ICO-3166-1 country codes
https://github.com/hollodotme/iso-country-codes

country-codes iso-3166-1 value-object

Last synced: about 1 month ago
JSON representation

A value object collection representing ICO-3166-1 country codes

Awesome Lists containing this project

README

        

![Unit tests](https://github.com/hollodotme/iso-country-codes/workflows/Unit%20tests/badge.svg)
![Static analysis](https://github.com/hollodotme/iso-country-codes/workflows/Static%20analysis/badge.svg)

# ISO-3166-1 country codes

This is a statically generated value object collection of [ISO-3166-1](https://en.wikipedia.org/wiki/ISO_3166-1) country
codes with their following representations:

* English short name
* French short name
* Alpha-2 code
* Alpha-3 code
* Numeric code

Source of the data is: https://www.iso.org/obp/ui/#search/code/

## Requirements

* PHP >= 7.4

## Installation

The recommended way to install this library is using [composer](https://getcomposer.org).

```bash
composer require "hollodotme/iso-country-codes"
```

## Usage

### From English short name

```php
getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();
```

**Prints:**
```
New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540
```

### From French short name

```php
getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();
```

**Prints:**
```
New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540
```

### From alpha-2 code

```php
getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();
```

**Prints:**
```
New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540
```

### From alpha-3 code

```php
getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();
```

**Prints:**
```
New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540
```

### From numeric code

```php
getEnglishShortName(), "\n";
echo $countryCode->getFrenchShortName(), "\n";
echo $countryCode->getAlpha2Code(), "\n";
echo $countryCode->getAlpha3Code(), "\n";
echo $countryCode->getNumericCode();
```

**Prints:**
```
New Caledonia
Nouvelle-Calédonie (la)
NC
NCL
540
```