Giter Club home page Giter Club logo

iso-country-codes's Introduction

Unit tests Static analysis

ISO-3166-1 country codes

This is a statically generated value object collection of 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.

composer require "hollodotme/iso-country-codes"

Usage

From English short name

<?php declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromEnglishShortName( 'New Caledonia' );

echo $countryCode->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 declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromFrenchShortName( 'Nouvelle-Calédonie (la)' );

echo $countryCode->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 declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromAlpha2Code( 'NC' );

echo $countryCode->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 declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromAlpha3Code( 'NCL' );

echo $countryCode->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 declare(strict_types=1);

use hollodotme\ISO\CountryCodes\CountryCode;

$countryCode = CountryCode::fromNumericCode( '540' );

echo $countryCode->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

iso-country-codes's People

Contributors

hollodotme avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.