You are here

function _countries_api_get_country in Country codes API 6

Function to return a country by code and name.

Parameters

$value: The country code value (in iso2, iso3, name or printable name format)

$format: The format to return country by

Return value

array with data of the country

6 calls to _countries_api_get_country()
CountriesAPITestCase::test_invalidformat_countries_api_get_country in tests/countries_api.test
Function to test invalid format passed to _countries_api_get_country
CountriesAPITestCase::test_results_countries_api_get_country in tests/countries_api.test
Function to test _countries_api_get_country returns a value
countries_api_iso2_get_country in ./countries_api.module
ISO 3166-1-alpha-2 code to country API function
countries_api_iso3_get_country in ./countries_api.module
ISO 3166-1-alpha-3 code to country API function
countries_api_numcode_get_country in ./countries_api.module
ISO 3166-1 numcode to country API function

... See full list

File

./countries_api.module, line 199
Countries API provides an API for official and up-to-date ISO 3166 country codes (alpha-2 and alpha-3) and names (official short names).

Code

function _countries_api_get_country($value, $format) {
  $value = trim(check_plain($value));
  switch ($format) {
    case COUNTRIES_API_FORMAT_ISO2:
      $result = db_query("SELECT iso2, name, printable_name, iso3, numcode FROM {countries_api_countries} WHERE iso2 = '%s'", $value);
      break;
    case COUNTRIES_API_FORMAT_ISO3:
      $result = db_query("SELECT iso2, name, printable_name, iso3, numcode FROM {countries_api_countries} WHERE iso3 = '%s'", $value);
      break;
    case COUNTRIES_API_FORMAT_NAME:
      $result = db_query("SELECT iso2, name, printable_name, iso3, numcode FROM {countries_api_countries} WHERE name = '%s'", $value);
      break;
    case COUNTRIES_API_FORMAT_PRINTABLE_NAME:
      $result = db_query("SELECT iso2, name, printable_name, iso3, numcode FROM {countries_api_countries} WHERE printable_name = '%s'", $value);
      break;
    case COUNTRIES_API_FORMAT_NUMCODE:
      $result = db_query("SELECT iso2, name, printable_name, iso3, numcode FROM {countries_api_countries} WHERE numcode = '%s'", $value);
      break;
    default:
      return FALSE;
  }
  return db_fetch_array($result);
}