James James - 2 months ago 7x
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



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');