This library is the PHP clone of the python library: alephdata/countrynames/
- PHP
7.0
and later. - Extensions: intl, yaml, mbstring, json.
$ git clone https://github.com/ClickSend/integration-library-country-names.git
In your php file, paste this code.
Make sure to edit the integration-library-country-names
directory to match your file structure.
Make sure the directory integration-library-country-names/lib/data
is writable, for caching purpose.
<?php
require_once 'integration-library-country-names/lib/CountryNames.php';
use CountryNamesLibrary\CountryNames;
var_dump('DE' == CountryNames::to_code('Germany'));
var_dump('DE' == CountryNames::to_code('Bundesrepublik Deutschland'));
var_dump('DE' == CountryNames::to_code('Bundesrepublik Deutschlan', $fuzzy=true));
var_dump('DE' == CountryNames::to_code('DE'));
var_dump('DEU' == CountryNames::to_code_3('Germany'));
you're all setup! To use the library as a composer package, see below.
First clone the repo to vendor directory in your project, then run composer autoload-dump command
$ git clone https://github.com/ClickSend/integration-library-country-names.git your-project-path/vendor/integration-library-country-names
$ composer autoload-dump
<?php
require_once 'vendor/autoload.php';
use CountryNamesLibrary\CountryNames;
var_dump('DE' == CountryNames::to_code('Germany'));
var_dump('DE' == CountryNames::to_code('Bundesrepublik Deutschland'));
var_dump('DE' == CountryNames::to_code('Bundesrepublik Deutschlan', $fuzzy=true));
var_dump('DE' == CountryNames::to_code('DE'));
var_dump('DEU' == CountryNames::to_code_3('Germany'));
If you updated the data.yaml file, then you need to delete the cache to reload the newly updated data, call this method once for every update:
CountryNames::_delete_cache();
To unit test run these commands, you need php version >= 7.3
composer install
./vendor/bin/phpunit test