I have the conversion between iso2 and iso3 working properly for the letter codes. But if I want to convert between iso2 and the iso3 number code or vice versa it starts acting strange.

For example. Entering an iso3 number code of '004' (Afghanistan) should return 'AF' but it returns 'DZ' (Algeria) instead. Algeria has a country code of '012'
So I tried '012' and it returned 'AM' (Armenia) which has a country code of '051'

this is the code I'm using:
$iso2 = country_load($numcode)->iso2;

Comments

AgentJay’s picture

Using iso2 to iso3 works fine for the letter codes.
$iso3 = country_load($iso2)->iso3;

It's just the numbers that are not working for me.

AgentJay’s picture

Title: Converting iso2 to iso3 » Converting numcode to iso2
Component: Countries configuration » Code
Category: Support request » Bug report
Issue summary: View changes
Alan D.’s picture

Category: Bug report » Support request
Status: Active » Fixed

As per the Readme

// Any property (iso2, iso3, num code or name) supplied by an end user
$country = countries_country_lookup($value);
$name = $country ? $country->name : '';

# 4 - Toggle between ISO character codes
$iso3 = country_load($iso2)->iso3;
$iso2 = $country = countries_country_lookup($iso3, 'iso3') ? $country->iso2 : '';

Status: Fixed » Closed (fixed)

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