You are here

function select_with_style_country_name_to_code in Select with Style 7

Converts a country name to a 2-letter ISO country code. Case-insensitve.

Parameters

type $country_name:

Return value

2-letter code or the original country name if not found

File

select_with_style/select_with_style.module, line 475
select_with_style.module

Code

function select_with_style_country_name_to_code($country_name) {
  require_once DRUPAL_ROOT . '/includes/locale.inc';
  $country_name_lower = drupal_strtolower($country_name);
  foreach ($country_names = country_get_list() as $code => $name) {
    if (drupal_strtolower($name) == $country_name_lower) {
      return $code;
    }
  }
  return $country_name;
}