James James - 1 year ago 73
PHP Question

Convert country codes

There are several methods on country codes.

I have a list of codes with 3-characters, like on this page:


Is there a simple way to convert them to 2-characters? Like "PT" from "POR" for Portugal.

Standard for 2-characters - http://en.wikipedia.org/wiki/ISO_3166-1_alpha-2


Answer Source

There is going to be no easy way because there is no particular scheme in the names of the country. For example PT from POR for Portugal and this can be different for other countries as well. You might want to create an array to hold two letters for each country.


$countries = array('PT' => 'Portugal', 'UK' => 'United Kingdom');
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download