-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcountryaliases.php
96 lines (86 loc) · 2.3 KB
/
countryaliases.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/*
Last updated 2013-03-20.
You have a UTF-8 string with a supposed country name.
Use this to validate that name, and get the country's ISO 3166 code.
All country aliases are in lowercase.
Make your string lowercase before trying to match.
Collection made by Johannes Lundberg
Send fixes to [email protected]
Use freely. Public domain.
*/
$countryaliases = array(
"antigua & barbuda"=>"AG",
"ascension island"=>"SH",
"bolivia"=>"BO",
"bosnia & herzegovina"=>"BA",
"british virgin islands"=>"VG",
"central african rep."=>"CF",
"congo, d.r."=>"CD",
"cote divoire"=>"CI",
"curacao"=>"CW",
"czech rep."=>"CZ",
"dem. rep. of the congo"=>"CD",
"democratic republic of the congo"=>"CD",
"dominican rep."=>"DO",
"east timor"=>"TL",
"faeroe islands"=>"FO",
"falkland islands"=>"FK",
"falkland islands, malvinas"=>"FK",
"guinea bissau"=>"GW",
"hongkong"=>"HK",
"hong kong, china"=>"HK",
"iran"=>"IR",
"ivory coast"=>"CI",
"lao"=>"LA",
"lao p.d.r."=>"LA",
"laos"=>"LA",
"korea, rep. of"=>"KP",
"macao, china"=>"MO",
"macau"=>"MO",
"macedonia"=>"MK",
"micronesia"=>"FM",
"moldova"=>"MD",
"north korea"=>"KP",
"palestine"=>"PS",
"palestinian territory"=>"PS",
"palestinian territory, occupied"=>"PS",
"reunion"=>"RE",
"russia"=>"RU",
"saint helena"=>"SH",
"sao tome & principe"=>"ST",
"sint maarten"=>"SX",
"south korea"=>"KR",
"st lucia"=>"LC",
"st vincent & the grenadines"=>"VC",
"st kitts & nevis"=>"KN",
"syria"=>"SY",
"taiwan"=>"TW",
"tanzania"=>"TZ",
"the former yugoslav republic of macedonia"=>"MK",
"trinidad & tobago"=>"TT",
"turks & caicos islands"=>"TC",
"us virgin islands"=>"VI",
"venezuela"=>"VE",
"vietnam"=>"VN",
);
/*
* Optional sample function - use if you like.
* Include 'countrynames.php' before this file.
*/
function string2countrycode($string) {
global $countryaliases,$countrynames;
// If countrynames.php is included, add lowercase versions to aliases
// Only do this the first function call, hence the 'sweden' key check
if (isset($countrynames) && !isset($countryaliases['sweden'])) {
foreach($countrynames as $code => $name) {
$countryaliases[mb_strtolower($name)] = $code;
}
}
// Make lowercase
$string = mb_strtolower($string);
// Is there a match for this alias?
return isset($countryaliases[$string]) ?
$countryaliases[$string] : '';
}
?>