view raw
James James - 9 months ago 30
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 -



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