Jump to Navigation

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.

Parameter(s)

None

Returns

An indexed array containing the list of each official ISO country codes and name as associative arrays, using the following keys:

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.

Parameter(s)

$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)

Returns

An indexed array containing a list using keys and values based on the paramaters.

function countries_api_get_options_array() : array

This function can be used to return an associative array of countries useful for FAPI select elements.

Parameter(s)

$first_element - The first value in the array (defaults to '' => 'Please Choose')

Returns

An indexed array in $country['iso2'] => $country['printable_name'] format.

function countries_api_get_formats() : array

This function returns an array of all available formats ('iso2', 'iso3', 'name', 'printable_name', 'numcode').

Parameter(s)

None

Returns

An array containing all available formats.

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.

Parameter(s)

$code - An ISO 3166-1-alpha-2 or ISO 3166-1-alpha-3 code as a string.

Returns

The corresponding country short name as a string. In case the country code doesn't match any country, null is returned.

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.

Parameter(s)

$code - An ISO 3166-1-alpha-2 or ISO 3166-1-alpha-3 code as a string.

Returns

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.

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.

Parameter(s)

$code - An ISO 3166-1-alpha-2 code as a string.

Returns

The corresponding country short name as a string. In case the country code doesn't match any country, null is returned.

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.

Parameter(s)

$code - An ISO 3166-1-alpha-2 code as a string.

Returns

The corresponding ISO 3166-1-alpha-3 code as a string. In case the country code doesn't match any country, null is returned.

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.

Parameter(s)

$code - An ISO 3166-1-alpha-2 code as a string.

Returns

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.

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.

Parameter(s)

$code - An ISO 3166-1-alpha-3 code as a string.

Returns

The corresponding country short name as a string. In case the country code doesn't match any country, null is returned.

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.

Parameter(s)

$code - An ISO 3166-1-alpha-3 code as a string.

Returns

The corresponding ISO 3166-1-alpha-2 code as a string. In case the country code doesn't match any country, null is returned.

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.

Parameter(s)

$code - An ISO 3166-1-alpha-3 code as a string.

Returns

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.

 

Comments

Anonymous's picture

Tom - This is great. Nice work!

Please share your thoughts, comments and suggestions...

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
If you have your own website, enter its address here and we will link to it for you. (please include http://).
eg. http://www.kirkdesigns.co.uk