Skip to content

Instantly share code, notes, and snippets.

@rjcorwin
Created August 8, 2013 17:32
Show Gist options
  • Select an option

  • Save rjcorwin/6186773 to your computer and use it in GitHub Desktop.

Select an option

Save rjcorwin/6186773 to your computer and use it in GitHub Desktop.
<?php
$codeToCountry = array(
"af" =>"Afghanistan",
"ax" =>"Aland Islands",
"al" =>"Albania",
"dz" =>"Algeria",
"as" =>"American Samoa",
"ad" =>"Andorra",
"ao" =>"Angola",
"ai" =>"Anguilla",
"aq" =>"Antarctica",
"ag" =>"Antigua and Barbuda",
"ar" =>"Argentina",
"am" =>"Armenia",
"aw" =>"Aruba",
"au" =>"Australia",
"at" =>"Austria",
"az" =>"Azerbaijan",
"bs" =>"Bahamas",
"bh" =>"Bahrain",
"bd" =>"Bangladesh",
"bb" =>"Barbados",
"by" =>"Belarus",
"be" =>"Belgium",
"bz" =>"Belize",
"bj" =>"Benin",
"bm" =>"Bermuda",
"bt" =>"Bhutan",
"bo" =>"Bolivia",
"bq" =>"Bonaire",
"ba" =>"Bosnia and Herzegovina",
"bw" =>"Botswana",
"bv" =>"Bouvet Island",
"br" =>"Brazil",
"bn" =>"Brunei Darussalam",
"bg" =>"Bulgaria",
"bf" =>"Burkina Faso",
"bi" =>"Burundi",
"kh" =>"Cambodia",
"cm" =>"Cameroon",
"ca" =>"Canada",
"cv" =>"Cape Verde",
"ky" =>"Cayman Islands",
"cf" =>"Central African Republic",
"td" =>"Chad",
"cl" =>"Chile",
"cn" =>"China",
"cx" =>"Christmas Island",
"cc" =>"Cocos (Keeling) Islands",
"co" =>"Colombia",
"km" =>"Comoros",
"cg" =>"Congo",
"cd" =>"Congo Republic of the",
"ck" =>"Cook Islands",
"cr" =>"Costa Rica",
"ci" =>"Cote d'Ivoire",
"hr" =>"Croatia",
"cu" =>"Cuba",
"cw" =>"Curacao",
"cy" =>"Cyprus",
"cz" =>"Czech Republic",
"dk" =>"Denmark",
"dj" =>"Djibouti",
"dm" =>"Dominica",
"do" =>"Dominican Republic",
"ec" =>"Ecuador",
"eg" =>"Egypt",
"sv" =>"El Salvador",
"gq" =>"Equatorial Guinea",
"er" =>"Eritrea",
"ee" =>"Estonia",
"et" =>"Ethiopia",
"fo" =>"Faroe Islands",
"fj" =>"Fiji",
"fi" =>"Finland",
"fr" =>"France",
"gf" =>"French Guiana",
"pf" =>"French Polynesia",
"ga" =>"Gabon",
"gm" =>"Gambia",
"ge" =>"Georgia",
"de" =>"Germany",
"gh" =>"Ghana",
"gi" =>"Gibraltar",
"gr" =>"Greece",
"gl" =>"Greenland",
"gd" =>"Grenada",
"gp" =>"Guadeloupe",
"gu" =>"Guam",
"gt" =>"Guatemala",
"gg" =>"Guernsey",
"gn" =>"Guinea",
"gw" =>"Guinea-Bissau",
"gy" =>"Guyana",
"ht" =>"Haiti",
"va" =>"Holy See (Vatican City State)",
"hn" =>"Honduras",
"hk" =>"Hong Kong",
"hu" =>"Hungary",
"is" =>"Iceland",
"in" =>"India",
"id" =>"Indonesia",
"ir" =>"Iran",
"iq" =>"Iraq",
"ie" =>"Ireland",
"im" =>"Isle of Man",
"il" =>"Israel",
"it" =>"Italy",
"jm" =>"Jamaica",
"jp" =>"Japan",
"je" =>"Jersey",
"jo" =>"Jordan",
"kz" =>"Kazakhstan",
"ke" =>"Kenya",
"ki" =>"Kiribati",
"kp" =>"Korea",
"kr" =>"Korea",
"kw" =>"Kuwait",
"kg" =>"Kyrgyzstan",
"lv" =>"Latvia",
"lb" =>"Lebanon",
"ls" =>"Lesotho",
"lr" =>"Liberia",
"ly" =>"Libyan Arab Jamahiriya",
"li" =>"Liechtenstein",
"lt" =>"Lithuania",
"lu" =>"Luxembourg",
"mo" =>"Macao",
"mk" =>"Macedonia",
"mg" =>"Madagascar",
"mw" =>"Malawi",
"my" =>"Malaysia",
"mv" =>"Maldives",
"ml" =>"Mali",
"mt" =>"Malta",
"mh" =>"Marshall Islands",
"mq" =>"Martinique",
"mr" =>"Mauritania",
"mu" =>"Mauritius",
"yt" =>"Mayotte",
"mx" =>"Mexico",
"fm" =>"Micronesia",
"md" =>"Moldova",
"mc" =>"Monaco",
"mn" =>"Mongolia",
"me" =>"Montenegro",
"ms" =>"Montserrat",
"ma" =>"Morocco",
"mz" =>"Mozambique",
"mm" =>"Myanmar",
"na" =>"Namibia",
"nr" =>"Nauru",
"np" =>"Nepal",
"nl" =>"Netherlands",
"nc" =>"New Caledonia",
"nz" =>"New Zealand",
"ni" =>"Nicaragua",
"ne" =>"Niger",
"ng" =>"Nigeria",
"nu" =>"Niue",
"nf" =>"Norfolk Island",
"mp" =>"N. Mariana Islands",
"no" =>"Norway",
"om" =>"Oman",
"pk" =>"Pakistan",
"pw" =>"Palau",
"ps" =>"Palestinian",
"pa" =>"Panama",
"pg" =>"Papua New Guinea",
"py" =>"Paraguay",
"pe" =>"Peru",
"ph" =>"Philippines",
"pn" =>"Pitcairn",
"pl" =>"Poland",
"pt" =>"Portugal",
"pr" =>"Puerto Rico",
"qa" =>"Qatar",
"re" =>"Reunion",
"ro" =>"Romania",
"ru" =>"Russian Federation",
"rw" =>"Rwanda",
"bl" =>"Saint Barthelemy",
"sh" =>"Saint Helena",
"kn" =>"Saint Kitts and Nevis",
"lc" =>"Saint Lucia",
"mf" =>"Saint Martin",
"pm" =>"Saint Pierre and Miquelon",
"vc" =>"Saint Vincent ",
"ws" =>"Samoa",
"sm" =>"San Marino",
"st" =>"Sao Tome and Principe",
"sa" =>"Saudi Arabia",
"sn" =>"Senegal",
"rs" =>"Serbia",
"sc" =>"Seychelles",
"sl" =>"Sierra Leone",
"sg" =>"Singapore",
"sx" =>"Sint Maarten (Dutch Part)",
"sk" =>"Slovakia",
"si" =>"Slovenia",
"sb" =>"Solomon Islands",
"so" =>"Somalia",
"za" =>"South Africa",
"gs" =>"South Georgia",
"ss" =>"South Sudan",
"es" =>"Spain",
"lk" =>"Sri Lanka",
"sd" =>"Sudan",
"sr" =>"Suriname",
"sj" =>"Svalbard and Jan Mayen",
"sz" =>"Swaziland",
"se" =>"Sweden",
"ch" =>"Switzerland",
"sy" =>"Syrian Arab Republic",
"tw" =>"Taiwan",
"tj" =>"Tajikistan",
"tz" =>"Tanzania",
"th" =>"Thailand",
"tl" =>"Timor-Leste",
"tg" =>"Togo",
"tk" =>"Tokelau",
"to" =>"Tonga",
"tt" =>"Trinidad and Tobago",
"tn" =>"Tunisia",
"tr" =>"Turkey",
"tm" =>"Turkmenistan",
"tc" =>"Turks and Caicos Islands",
"tv" =>"Tuvalu",
"ug" =>"Uganda",
"ua" =>"Ukraine",
"ae" =>"United Arab Emirates",
"gb" =>"United Kingdom",
"us" =>"United States",
"uy" =>"Uruguay",
"uz" =>"Uzbekistan",
"vu" =>"Vanuatu",
"ve" =>"Venezuela",
"vn" =>"Viet Nam",
"vg" =>"Virgin Islands, British",
"vi" =>"Virgin Islands, U.S.",
"wf" =>"Wallis and Futuna",
"eh" =>"Western Sahara",
"ye" =>"Yemen",
"zm" =>"Zambia",
"zw" =>"Zimbabwe"
);
$countryToCode = array(
"Afghanistan" => "af",
"Aland Islands" => "ax",
"Albania" => "al",
"Algeria" => "dz",
"American Samoa" => "as",
"Andorra" => "ad",
"Angola" => "ao",
"Anguilla" => "ai",
"Antarctica" => "aq",
"Antigua and Barbuda" => "ag",
"Argentina" => "ar",
"Armenia" => "am",
"Aruba" => "aw",
"Australia" => "au",
"Austria" => "at",
"Azerbaijan" => "az",
"Bahamas" => "bs",
"Bahrain" => "bh",
"Bangladesh" => "bd",
"Barbados" => "bb",
"Belarus" => "by",
"Belgium" => "be",
"Belize" => "bz",
"Benin" => "bj",
"Bermuda" => "bm",
"Bhutan" => "bt",
"Bolivia" => "bo",
"Bonaire" => "bq",
"Bosnia and Herzegovina" => "ba",
"Botswana" => "bw",
"Bouvet Island" => "bv",
"Brazil" => "br",
"Brunei Darussalam" => "bn",
"Bulgaria" => "bg",
"Burkina Faso" => "bf",
"Burundi" => "bi",
"Cambodia" => "kh",
"Cameroon" => "cm",
"Canada" => "ca",
"Cape Verde" => "cv",
"Cayman Islands" => "ky",
"Central African Republic" => "cf",
"Chad" => "td",
"Chile" => "cl",
"China" => "cn",
"Christmas Island" => "cx",
"Cocos (Keeling) Islands" => "cc",
"Colombia" => "co",
"Comoros" => "km",
"Congo" => "cg",
"Congo Republic of the" => "cd",
"Cook Islands" => "ck",
"Costa Rica" => "cr",
"Cote d'Ivoire" => "ci",
"Croatia" => "hr",
"Cuba" => "cu",
"Curacao" => "cw",
"Cyprus" => "cy",
"Czech Republic" => "cz",
"Denmark" => "dk",
"Djibouti" => "dj",
"Dominica" => "dm",
"Dominican Republic" => "do",
"Ecuador" => "ec",
"Egypt" => "eg",
"El Salvador" => "sv",
"Equatorial Guinea" => "gq",
"Eritrea" => "er",
"Estonia" => "ee",
"Ethiopia" => "et",
"Faroe Islands" => "fo",
"Fiji" => "fj",
"Finland" => "fi",
"France" => "fr",
"French Guiana" => "gf",
"French Polynesia" => "pf",
"Gabon" => "ga",
"Gambia" => "gm",
"Georgia" => "ge",
"Germany" => "de",
"Ghana" => "gh",
"Gibraltar" => "gi",
"Greece" => "gr",
"Greenland" => "gl",
"Grenada" => "gd",
"Guadeloupe" => "gp",
"Guam" => "gu",
"Guatemala" => "gt",
"Guernsey" => "gg",
"Guinea" => "gn",
"Guinea-Bissau" => "gw",
"Guyana" => "gy",
"Haiti" => "ht",
"Holy See (Vatican City State)" => "va",
"Honduras" => "hn",
"Hong Kong" => "hk",
"Hungary" => "hu",
"Iceland" => "is",
"India" => "in",
"Indonesia" => "id",
"Iran" => "ir",
"Iraq" => "iq",
"Ireland" => "ie",
"Isle of Man" => "im",
"Israel" => "il",
"Italy" => "it",
"Jamaica" => "jm",
"Japan" => "jp",
"Jersey" => "je",
"Jordan" => "jo",
"Kazakhstan" => "kz",
"Kenya" => "ke",
"Kiribati" => "ki",
"Korea" => "kp",
"Korea" => "kr",
"Kuwait" => "kw",
"Kyrgyzstan" => "kg",
"Latvia" => "lv",
"Lebanon" => "lb",
"Lesotho" => "ls",
"Liberia" => "lr",
"Libyan Arab Jamahiriya" => "ly",
"Liechtenstein" => "li",
"Lithuania" => "lt",
"Luxembourg" => "lu",
"Macao" => "mo",
"Macedonia" => "mk",
"Madagascar" => "mg",
"Malawi" => "mw",
"Malaysia" => "my",
"Maldives" => "mv",
"Mali" => "ml",
"Malta" => "mt",
"Marshall Islands" => "mh",
"Martinique" => "mq",
"Mauritania" => "mr",
"Mauritius" => "mu",
"Mayotte" => "yt",
"Mexico" => "mx",
"Micronesia" => "fm",
"Moldova" => "md",
"Monaco" => "mc",
"Mongolia" => "mn",
"Montenegro" => "me",
"Montserrat" => "ms",
"Morocco" => "ma",
"Mozambique" => "mz",
"Myanmar" => "mm",
"Namibia" => "na",
"Nauru" => "nr",
"Nepal" => "np",
"Netherlands" => "nl",
"New Caledonia" => "nc",
"New Zealand" => "nz",
"Nicaragua" => "ni",
"Niger" => "ne",
"Nigeria" => "ng",
"Niue" => "nu",
"Norfolk Island" => "nf",
"N. Mariana Islands" => "mp",
"Norway" => "no",
"Oman" => "om",
"Pakistan" => "pk",
"Palau" => "pw",
"Palestinian" => "ps",
"Panama" => "pa",
"Papua New Guinea" => "pg",
"Paraguay" => "py",
"Peru" => "pe",
"Philippines" => "ph",
"Pitcairn" => "pn",
"Poland" => "pl",
"Portugal" => "pt",
"Puerto Rico" => "pr",
"Qatar" => "qa",
"Reunion" => "re",
"Romania" => "ro",
"Russian Federation" => "ru",
"Rwanda" => "rw",
"Saint Barthelemy" => "bl",
"Saint Helena" => "sh",
"Saint Kitts and Nevis" => "kn",
"Saint Lucia" => "lc",
"Saint Martin" => "mf",
"Saint Pierre and Miquelon" => "pm",
"Saint Vincent " => "vc",
"Samoa" => "ws",
"San Marino" => "sm",
"Sao Tome and Principe" => "st",
"Saudi Arabia" => "sa",
"Senegal" => "sn",
"Serbia" => "rs",
"Seychelles" => "sc",
"Sierra Leone" => "sl",
"Singapore" => "sg",
"Sint Maarten (Dutch Part)" => "sx",
"Slovakia" => "sk",
"Slovenia" => "si",
"Solomon Islands" => "sb",
"Somalia" => "so",
"South Africa" => "za",
"South Georgia" => "gs",
"South Sudan" => "ss",
"Spain" => "es",
"Sri Lanka" => "lk",
"Sudan" => "sd",
"Suriname" => "sr",
"Svalbard and Jan Mayen" => "sj",
"Swaziland" => "sz",
"Sweden" => "se",
"Switzerland" => "ch",
"Syrian Arab Republic" => "sy",
"Taiwan" => "tw",
"Tajikistan" => "tj",
"Tanzania" => "tz",
"Thailand" => "th",
"Timor-Leste" => "tl",
"Togo" => "tg",
"Tokelau" => "tk",
"Tonga" => "to",
"Trinidad and Tobago" => "tt",
"Tunisia" => "tn",
"Turkey" => "tr",
"Turkmenistan" => "tm",
"Turks and Caicos Islands" => "tc",
"Tuvalu" => "tv",
"Uganda" => "ug",
"Ukraine" => "ua",
"United Arab Emirates" => "ae",
"United Kingdom" => "gb",
"United States" => "us",
"Uruguay" => "uy",
"Uzbekistan" => "uz",
"Vanuatu" => "vu",
"Venezuela" => "ve",
"Viet Nam" => "vn",
"Virgin Islands, British" => "vg",
"Virgin Islands, U.S." => "vi",
"Wallis and Futuna" => "wf",
"Western Sahara" => "eh",
"Yemen" => "ye",
"Zambia" => "zm",
"Zimbabwe" => "zw",
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment