PHP code example of chibifr / country-converter
1. Go to this page and download the library: Download chibifr/country-converter 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/ */
chibifr / country-converter example snippets
// Require the composer's vendor autoload file
a new Converter object
$converter = new Converter();
// Get a country name from its ISO code
echo $converter->getCountryName('jp'); // will echo "Japan"
// Get a country ISO code from its name
echo $converter->getCountryCode('France'); // will echo "FR"
// Require the composer's vendor autoload file
a new Converter object
$converter = new Converter();
// Get a country name from its ISO code
try {
echo $converter->getCountryName('jp'); // will echo "Japan"
} catch (InvalidCountryNameException $e) {
die($e->getMessage());
}
// Get a country ISO code from its name
try {
echo $converter->getCountryCode('France'); // will echo "FR"
} catch (InvalidCountryCodeException $e) {
die($e->getMessage());
}