This package provides collections of various ISO standards (e.g. country, language, language scripts, and currency
names) as PHP objects for use in your code. The data is generated from Debian's pkg-isocodes
.
This lists the 2-letter country code and "short" country name.
This is a further development of ISO 639-2. All codes of ISO 639-2 are included in ISO 639-3. ISO 639-3 attempts to provide as complete an enumeration of languages as possible, including living, extinct, ancient, and constructed languages, whether major or minor, written or unwritten.
This lists the currency codes and names.
This lists the language scripts names.
The ISO 3166 standard includes a "Country Subdivision Code", giving a code for the names of the principal administrative subdivisions of the countries coded in ISO 3166.
No changes to the data will be accepted. This is a pure wrapper around the ISO standard using the pkg-isocodes
databases from Debian as is. If you find errors in the data you should file an issues on Debian's Bug Tracker.
Via Composer
$ composer require jeremyworboys/isocodes
All standards are available through database objects that are populated on first access. They are singletons to prevent
loading the data from the filesystem on each request. Indices are pre-generated in the data files and rehydrated when
the database object is constructed. Each database object is countable
and traversable
as you will see in the
following examples.
Countries are accessible through a database object and can be queried on various indices (alpha2, alpha3, numeric, officialName, commonName, name):
// Get the countries database singleton
$countries = JeremyWorboys\IsoCodes\IsoCodes::countries();
// Countries are countable
count($countries); // 249
// Countries are traversable
foreach ($countries as $country) {
echo $country->getName();
}
// Get an array of all countries
$allCountries = $countries->findAll();
// Get an array of all countries where the array key is the alpha2 code
$allCountries = $countries->findAllByAlpha2();
// Get an array of all countries where the array key is the country name
$allCountries = $countries->findAllByName();
Specific countries can be looked up by their various codes and provide the information included in the standard as getter methods:
// Get a single country by alpha2 code
$australia = $countries->findByAlpha2('AU');
$australia->getAlpha2(); // "AU"
$australia->getAlpha3(); // "AUS"
$australia->getNumeric(); // "036"
$australia->getOfficialName(); // ""
$australia->getCommonName(); // ""
$australia->getName(); // "Australia"
$ composer test
Please see CONTRIBUTING for details.
The LPGL 2.1 License (LPGL 2.1). Please see the License File for more information.