-
Notifications
You must be signed in to change notification settings - Fork 0
/
helper-php-code-for-countries
77 lines (64 loc) · 5.15 KB
/
helper-php-code-for-countries
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
<?php
// #################################################################################### //
// This is helper file. See main readme.
// To quickly build this script, use i.e.: http://sandbox.onlinephpfunctions.com
// #################################################################################### //
// all countries array
$countries_ARRAY=['Afghanistan','Albania','Algeria','American Samoa','Andorra','Angola','Anguilla','Antarctica','Antigua And Barbuda','Argentina','Armenia','Aruba','Australia','Austria','Azerbaijan','Bahamas','Bahrain','Bangladesh','Barbados','Belarus','Belgium','Belize','Benin','Bermuda','Bhutan','Bolivia','Bosnia And Herzegovina','Botswana','Bouvet Island','Brazil','British Indian Ocean Territory','Brunei Darussalam','Bulgaria','Burkina Faso','Burundi','Cambodia','Cameroon','Canada','Cape Verde','Cayman Islands','Central African Republic','Chad','Chile','China','Christmas Island','Cocos Islands','Colombia','Comoros','Congo','Cook Islands','Costa Rica','Cote D\'ivoire','Croatia','Cuba','Cyprus','Czech Republic','Denmark','Djibouti','Dominica','Dominican Republic','East Timor','Ecuador','Egypt','El Salvador','Equatorial Guinea','Eritrea','Estonia','Ethiopia','Falkland Islands','Faroe Islands','Fiji','Finland','France','French Guiana','French Polynesia','French Southern Territories','Gabon','Gambia','Georgia','Germany','Ghana','Gibraltar','Greece','Greenland','Grenada','Guadeloupe','Guam','Guatemala','Guinea','Guinea-bissau','Guyana','Haiti','Heard Island And Mcdonald Islands','Honduras','Hong Kong','Hungary','Iceland','India','Indonesia','Iran','Iraq','Ireland','Israel','Italy','Jamaica','Japan','Jordan','Kazakstan','Kenya','Kiribati','Korea','Kosovo','Kuwait','Kyrgyzstan','Latvia','Lebanon','Lesotho','Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania','Luxembourg','Macau','Macedonia','Madagascar','Malawi','Malaysia','Maldives','Mali','Malta','Marshall Islands','Martinique','Mauritania','Mauritius','Mayotte','Mexico','Micronesia','Moldova','Monaco','Mongolia','Montserrat','Montenegro','Morocco','Mozambique','Myanmar','Namibia','Nauru','Nepal','Netherlands','Netherlands Antilles','New Caledonia','New Zealand','Nicaragua','Niger','Nigeria','Niue','Norfolk Island','Northern Mariana Islands','Norway','Oman','Pakistan','Palau','Palestina','Panama','Papua New Guinea','Paraguay','Peru','Philippines','Pitcairn','Poland','Portugal','Puerto Rico','Qatar','Reunion','Romania','Russian Federation','Rwanda','Saint Helena','Saint Kitts And Nevis','Saint Lucia','Saint Pierre And Miquelon','Saint Vincent And The Grenadines','Samoa','San Marino','Sao Tome And Principe','Saudi Arabia','Senegal','Serbia','Seychelles','Sierra Leone','Singapore','Slovakia','Slovenia','Solomon Islands','Somalia','South Africa','South Georgia And The South Sandwich Islands','Spain','Sri Lanka','Sudan','Suriname','Svalbard And Jan Mayen','Swaziland','Sweden','Switzerland','Syrian Arab Republic','Taiwan','Tajikistan','Tanzania','Thailand','Togo','Tokelau','Tonga','Trinidad And Tobago','Tunisia','Turkey','Turkmenistan','Turks And Caicos Islands','Tuvalu','Uganda','Ukraine','United Arab Emirates','United Kingdom','United States','United States Minor Outlying Islands','Uruguay','Uzbekistan','Vanuatu','Venezuela','VietNam','Virgin Islands','Wallis And Futuna','Western Sahara','Yemen','Zambia','Zimbabwe'];
// here, define the "exclusion cases"
$exclusions_array = [
'Benin' =>['Bening'],
'Cuba' =>['Cubal','Cubase'],
'Georgia' =>['united states', 'USA', 'U.S.', 'US', ' GA', 'atlanta', 'german'], // (because Georgia is also US state, we needed such exlcusions
'Greece' =>['Greecela','Greecemania'],
'Greece' =>['Greecela','Greecemania'],
'Slovakia' =>['TN,','USA'],
];
// ############################## No need to change below ############################## //
// countries table
$n=[];
echo 'countries as
(
';
for ($i=0; $i<count($countries_ARRAY); $i++)
{
echo " select ".($i+1).($i==0 ? " id":"") .", '". str_replace('\'', '\'\'', $countries_ARRAY[$i])."'". ( $i<count($countries_ARRAY)-1 ? ($i==0 ? " name":"")." union" : "") . "\r\n" ;
}
echo ')';
// country_writings table
echo ',
country_writings as
(
';
for ($i=0; $i<count($countries_ARRAY); $i++)
{
echo " select ".($i+1).($i==0 ? " countryid":"") .", '". str_replace('\'', '\'\'', $countries_ARRAY[$i])."'". ( $i<count($countries_ARRAY)-1 ? ($i==0 ? " altname":"")." union" : "") . "\r\n" ;
}
echo ')';
// exclusions table
echo ',
exclude_writings as
(
';
$i=0;
foreach($exclusions_array as $country=>$exclusions)
{
$j=0;
$country_id= array_search($country,$countries_ARRAY);
foreach($exclusions as $exclusion)
{
$is_first=$i==0 && $j==0;
$is_last = $i==count($exclusions_array)-1 && $j==count($exclusions)-1;
echo " select ".($country_id+1).($is_first ? " countryid":"") .", '". str_replace('\'', '\'\'', $exclusion)."'". ( !$is_last ? ($is_first ? " altname":"")." union" : "") . "\r\n" ;
$j++;
}
$i++;
}
echo ')';
/*
-- // extra refinements, i.e. for Slovak, if country name is not mentioned, and only city name is mentioned
-- select ID_for_Slovak_here, 'banska' union
-- select ID_for_Slovak_here, 'martin' union
-- select ID_for_Slovak_here, 'komarno' union
*/
?>