function continents_api_get_countries in Country codes API 5
Same name and namespace in other branches
- 6 contrib/continents_api/continents_api.module \continents_api_get_countries()
Function to get a region by iso2 country name
Parameters
$continent_code: A continent code. E.g. 'EU' for Europe.
Return value
A list of countries in the given continent. In ISO-2 format. Use the countries_api module to convert to other country representations. Returns NULL in case of an invalid continent code.
File
- contrib/
continents_api/ continents_api.module, line 40 - Continents API provides an API for official and up-to-date list of continents and their countries. Countries are provided in ISO 3166 alpha-2 country codes. Source: http://en.wikipedia.org/wiki/List_of_countries_by_continent_(data_file)
Code
function continents_api_get_countries($continent_code) {
// Validate the continent code.
$valid_continent_codes = array_keys(continents_api_get_continents());
if (!in_array($continent_code, $valid_continent_codes)) {
return NULL;
}
// Look up the countries for the given continent.
$result = db_query("SELECT country FROM {continents_api_continents} WHERE continent = '%s'", $continent_code);
$continents = array();
while ($row = db_fetch_object($result)) {
$countries[] = $row->country;
}
return $countries;
}