The Country Codes API
The Country Codes API Provides an API for official ISO 3166 country codes and names. Please visit the Maintenance agency website at http://www.iso.org/iso/country_codes/ for more information about ISO 3166.
Global operations
function countries_api_get_list() : array
This function returns the full list of official ISO country codes and names.
- None
- An indexed array containing the list of each official ISO country codes and name as associative arrays, using the following keys:
- name - Returns the country name (upper case)
- printable_name - Returns the country name (mixed case)
- iso2 - Returns the country ISO 3166-1 alpha-2 code.
- iso3 - Returns the country ISO 3166-1 alpha-3 code.
- numcode - Returns the country ISO 3166-1 numeric code.
- name - Returns the country name (upper case)
Parameter(s)
Returns
function countries_api_get_array() : array
This function can be used to return an associative array of countries with key/values based on args. Can be useful to get results for FAPI form options.
- $key_format - The format of the key (a value from countries_api_formats)
$value_format - The format of the value (a value from countries_api_formats) - An indexed array containing a list using keys and values based on the paramaters.
Parameter(s)
Returns
function countries_api_get_options_array() : array
This function can be used to return an associative array of countries useful for FAPI select elements.
- $first_element - The first value in the array (defaults to '' => 'Please Choose')
- An indexed array in $country['iso2'] => $country['printable_name'] format.
Parameter(s)
Returns
function countries_api_get_formats() : array
This function returns an array of all available formats ('iso2', 'iso3', 'name', 'printable_name', 'numcode').
- None
- An array containing all available formats.
Parameter(s)
Returns
function countries_api_get_name($code) : string
This function gets either an ISO 3166-1-alpha-2 or ISO 3166-1-alpha-3 code in parameter and returns the corresponding country short name.
- $code - An ISO 3166-1-alpha-2 or ISO 3166-1-alpha-3 code as a string.
- The corresponding country short name as a string. In case the country code doesn't match any country, null is returned.
Parameter(s)
Returns
function countries_api_get_country($code) : array
This function gets either an ISO 3166-1-alpha-2 or ISO 3166-1-alpha-3 code in parameter and returns an array representing the corresponding country.
- $code - An ISO 3166-1-alpha-2 or ISO 3166-1-alpha-3 code as a string.
- An associative array, using the keys as described in countries_api_get_list(). In case the country code doesn't match any country, null is returned.
Parameter(s)
Returns
ISO 3166-1-alpha-2 code operations
function countries_api_iso2_get_name($code) : string
This function gets an ISO 3166-1-alpha-2 code in parameter and returns the corresponding country short name.
- $code - An ISO 3166-1-alpha-2 code as a string.
- The corresponding country short name as a string. In case the country code doesn't match any country, null is returned.
Parameter(s)
Returns
function countries_api_iso2_get_iso3($code) : string
This function gets an ISO 3166-1-alpha-2 code in parameter and returns the corresponding ISO 3166-1-alpha-3 code.
- $code - An ISO 3166-1-alpha-2 code as a string.
- The corresponding ISO 3166-1-alpha-3 code as a string. In case the country code doesn't match any country, null is returned.
Parameter(s)
Returns
function countries_api_iso2_get_country($code) : array
This function gets an ISO 3166-1-alpha-2 code in parameter and returns an array representing the corresponding country.
- $code - An ISO 3166-1-alpha-2 code as a string.
- An associative array, using the keys as described in countries_api_get_list(). In case the country code doesn't match any country, null is returned.
Parameter(s)
Returns
ISO 3166-1-alpha-3 code operations
function countries_api_iso3_get_name($code) : string
This function gets an ISO 3166-1-alpha-3 code in parameter and returns the corresponding country short name.
- $code - An ISO 3166-1-alpha-3 code as a string.
- The corresponding country short name as a string. In case the country code doesn't match any country, null is returned.
Parameter(s)
Returns
function countries_api_iso3_get_iso2($code) : string
This function gets an ISO 3166-1-alpha-3 code in parameter and returns the corresponding ISO 3166-1-alpha-2 code.
- $code - An ISO 3166-1-alpha-3 code as a string.
- The corresponding ISO 3166-1-alpha-2 code as a string. In case the country code doesn't match any country, null is returned.
Parameter(s)
Returns
function countries_api_iso3_get_country($code) : array
This function gets an ISO 3166-1-alpha-3 code in parameter and returns an array representing the corresponding country.
- $code - An ISO 3166-1-alpha-3 code as a string.
- An associative array, using the keys as described in countries_api_get_list(). In case the country code doesn't match any country, null is returned.
Parameter(s)
Returns
LATEST ARTICLES
TODAY'S MOST POPULAR
-
4th Sep 08
-
8th Aug 08
-
11th Jul 08
MOST POPULAR ARTICLES
RECENT COMMENTS
-
1 day 12 hours ago
-
4 days 2 hours ago
-
4 days 7 hours ago
-
4 days 13 hours ago
-
5 days 6 hours ago

Comments
3rd Jun 2009, 3:36pm
Tom - This is great. Nice work!
Please share your thoughts, comments and suggestions...