1. Go to this page and download the library: Download sokil/php-isocodes library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
sokil / php-isocodes example snippets
$databaseBaseDir = '/var/isocodes';
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory($databaseBaseDir);
// gettext driver
$isoCodes = new IsoCodesFactory();
$isoCodes = new IsoCodesFactory(null, new GettextExtensionDriver());
// symfony driver
$driver = new SymfonyTranslationDriver();
$driver->setLocale('uk_UA');
$isoCodes = new IsoCodesFactory(
null,
$driver
);
// dummy driver
$isoCodes = new IsoCodesFactory(
null,
new DummyDriver()
);
// gettext driver
$isoCodes = new IsoCodesFactory();
$isoCodes = new IsoCodesFactory(null, new GettextExtensionDriver());
// define locale
putenv('LANGUAGE=uk_UA.UTF-8');
putenv('LC_ALL=uk_UA.UTF-8');
setlocale(LC_ALL, 'uk_UA.UTF-8');
// init database
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
// get languages database
$languages = $isoCodes->getLanguages();
// get local name of language
echo $languages->getByAlpha2('uk')->getLocalName(); // will print 'українська'
$driver = new SymfonyTranslationDriver();
$driver->setLocale('uk_UA');
$isoCodes = new IsoCodesFactory(
null,
$driver
);
$isoCodes = new IsoCodesFactory(
null,
new DummyDriver()
);
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$languages = $isoCodes->getLanguages();
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$country = $isoCodes->getCountries()->getByAlpha2('UA');
echo $country->getFlag();
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$isoCodes->getCountries()->getByAlpha2('UA')->getLocalName();
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$isoCodes->getCountries()->getByAlpha3('UKR')->getLocalName();
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
$isoCodes->getCountries()->getByNumericCode('804')->getLocalName();
$isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
foreach($isoCodes->getCountries() as $country) {
echo $country->getLocalName();
}
$isoCodes = new IsoCodesFactory();
$subDivisions = $isoCodes->getSubdivisions();
// get subdivision by code
$subDivision = $subDivisions->getByCode('UA-43');
// get subdivision code
$subDivision->getCode(); // UA-43
// get subdivision name
$subDivision->getName(); // Respublika Krym
// get localised subdivision name
$subDivision->getLocalName(); // Автономна Республіка Крим
// get subdivision type
$subDivision->getType(); // 'Autonomous republic'
$isoCodes = new IsoCodesFactory();
$languages = $isoCodes->getLanguages();
$language = $languages->getByAlpha2('uk');
$language->getAlpha2(); // uk
$language->getName(); // Ukrainian
$language->getLocalName(); // українська
$language->getAlpha3(); // ukr
// Scope of denotation, see mote at https://iso639-3.sil.org/about/scope
$language->getScope(); // I
// Type of language, see https://iso639-3.sil.org/about/types
$language->getType(); // L
$language->getInvertedName(); // null
composer
composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.