PHP Classes

PHP Country Code to Country Name: Validate country code and get the respective name

Recommend this page to a friend!
  Info   Documentation   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 313 All time: 7,286 This week: 206Up
Version License PHP version Categories
countrycode 1.0.4Custom (specified...5PHP 5, Geography, Validation
Description 

Author

This class can validate country code and get the respective name.

It can take a given country code with two letters and determine if it corresponds to a valid country.

The class can also get the name of a country given the respective two letter code.

Innovation Award
PHP Programming Innovation award nominee
September 2018
Number 4
Many applications need to take the country code as parameter for their own purposes.

This class can take the two letter code of country and determine if it corresponds to a valid code. It can also return the respective country name.

Manuel Lemos
Picture of Peter Kahl
  Performance   Level  
Name: Peter Kahl <contact>
Classes: 37 packages by
Country: United Kingdom
Innovation award
Innovation award
Nominee: 23x

Winner: 2x

Documentation

CountryCode

Downloads License If this project has business value for you then don't hesitate to support me with a small donation.

Methods for working with 2-character country codes (validation, name from code).

??CAUTION

When using method getName(), multibyte strings will be returned.

Usage Exaples

use peterkahl\CountryCode\CountryCode;

# Validate a country code string:
if (CountryCode::isValid('uk'))
{
  echo 'valid';
}
else
{
  echo 'invalid';
}

# Get name from country code:
echo CountryCode::getName('RE'); # Réunion

  Files folder image Files (4)  
File Role Description
Files folder imagesrc (1 file)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files (4)  /  src  
File Role Description
  Plain text file CountryCode.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:313
This week:0
All time:7,286
This week:206Up