Hi guys,

Any chance of some help? I'm have my country numcode from IP. So , 826 for the UK.

I'd like to return the country name using the API. I've had a look at the docs and it seems all the API call take parameters for ISO2 and 3 only?

I can return the complete country list using:

 $countries  = countries_api_get_list();

But am struggling to access the name using the numcode from the array?

Comments

VinceW’s picture

Status: Active » Needs review

Perhaps this will work for you: #933266: Support for ISO 3166-1 numeric

But it would be cleaner to have a piece of code in the module like:

/**
 * ISO 3166-1 numcode to country API function
 * @param $code 
 *  An string containg the numcode value
 * @return string
 *  Returns an array containing the country fields
 */
function countries_api_numcode_get_country($code) {
  return _countries_api_numcode_get_country($code, 'numcode');
}


/**
 * ISO 3166-1 numcode to country name API function
 * @param $code
 *  numcode to search by.
 * @return string
 *  Returns country name as a string.
 */
function countries_api_numcode_get_name($code) {
  $_country = countries_api_numcode_get_country($code);
  if (!is_null($_country)) {
    return $_country['name'];
  }
  return NULL;
}

that way you could use:

$my_country_name = countries_api_numcode_get_name(826)

Perhaps in a next release? :-)

Best,
VinceW

mrfelton’s picture

Status: Needs review » Fixed

Thanks,
These functions have been added to the D5 and D6 versions.

hixster’s picture

cool

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.