alcohol/iso3166

A PHP library providing ISO 3166-1 data.

Build Status License

What is ISO 3166-1

ISO 3166-1 is part of the ISO 3166 standard published by the International Organization for Standardization (ISO), and defines codes for the names of countries, dependent territories, and special areas of geographical interest. The official name of the standard is Codes for the representation of names of countries and their subdivisions – Part 1: Country codes. It defines three sets of country codes:

-- Wikipedia

Installing

$ composer require alcohol/iso3166

Using

Code:

<?php

use Alcohol\ISO3166\ISO3166;

$iso3166 = new ISO3166();

// methods defined by interface Alcohol\ISO3166\DataProvider
$iso3166->getByAlpha2('NL');
$iso3166->getByAlpha3('NLD');
$iso3166->getByNumeric('528');

// methods provided for convenience
$iso3166->getAll();
foreach ($iso3166 as $key => $value) {
    // simple iterator implementation using a generator (uses alpha2 for keys)
}
foreach ($iso3166->listBy(ISO3166::KEY_ALPHA3) as $key => $value) {
    // use a specific generator to iterate using other available keys
    // constants available are KEY_ALPHA2, KEY_ALPHA3, KEY_NUMERIC
}

The data returned is in the format of:

Array
(
    [name] => Netherlands
    [alpha2] => NL
    [alpha3] => NLD
    [numeric] => 528
    [currency] => EUR
)

Contributing

Feel free to submit a pull request or create an issue.

License

alcohol/iso3166 is licensed under the MIT license.

Source(s)