Last active
September 6, 2015 22:01
-
-
Save vhdm/7da50ee3c4ba84f70cc4 to your computer and use it in GitHub Desktop.
Get country list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function countrylist($action = 'dropdown', $selectedid = null) { | |
$country_list = array( | |
"Afghanistan", | |
"Albania", | |
"Algeria", | |
"Andorra", | |
"Angola", | |
"Antigua and Barbuda", | |
"Argentina", | |
"Armenia", | |
"Australia", | |
"Austria", | |
"Azerbaijan", | |
"Bahamas", | |
"Bahrain", | |
"Bangladesh", | |
"Barbados", | |
"Belarus", | |
"Belgium", | |
"Belize", | |
"Benin", | |
"Bhutan", | |
"Bolivia", | |
"Bosnia and Herzegovina", | |
"Botswana", | |
"Brazil", | |
"Brunei", | |
"Bulgaria", | |
"Burkina Faso", | |
"Burundi", | |
"Cambodia", | |
"Cameroon", | |
"Canada", | |
"Cape Verde", | |
"Central African Republic", | |
"Chad", | |
"Chile", | |
"China", | |
"Colombi", | |
"Comoros", | |
"Congo (Brazzaville)", | |
"Congo", | |
"Costa Rica", | |
"Cote d'Ivoire", | |
"Croatia", | |
"Cuba", | |
"Cyprus", | |
"Czech Republic", | |
"Denmark", | |
"Djibouti", | |
"Dominica", | |
"Dominican Republic", | |
"East Timor (Timor Timur)", | |
"Ecuador", | |
"Egypt", | |
"El Salvador", | |
"Equatorial Guinea", | |
"Eritrea", | |
"Estonia", | |
"Ethiopia", | |
"Fiji", | |
"Finland", | |
"France", | |
"Gabon", | |
"Gambia, The", | |
"Georgia", | |
"Germany", | |
"Ghana", | |
"Greece", | |
"Grenada", | |
"Guatemala", | |
"Guinea", | |
"Guinea-Bissau", | |
"Guyana", | |
"Haiti", | |
"Honduras", | |
"Hungary", | |
"Iceland", | |
"India", | |
"Indonesia", | |
"Iran", | |
"Iraq", | |
"Ireland", | |
"Israel", | |
"Italy", | |
"Jamaica", | |
"Japan", | |
"Jordan", | |
"Kazakhstan", | |
"Kenya", | |
"Kiribati", | |
"Korea, North", | |
"Korea, South", | |
"Kuwait", | |
"Kyrgyzstan", | |
"Laos", | |
"Latvia", | |
"Lebanon", | |
"Lesotho", | |
"Liberia", | |
"Libya", | |
"Liechtenstein", | |
"Lithuania", | |
"Luxembourg", | |
"Macedonia", | |
"Madagascar", | |
"Malawi", | |
"Malaysia", | |
"Maldives", | |
"Mali", | |
"Malta", | |
"Marshall Islands", | |
"Mauritania", | |
"Mauritius", | |
"Mexico", | |
"Micronesia", | |
"Moldova", | |
"Monaco", | |
"Mongolia", | |
"Morocco", | |
"Mozambique", | |
"Myanmar", | |
"Namibia", | |
"Nauru", | |
"Nepa", | |
"Netherlands", | |
"New Zealand", | |
"Nicaragua", | |
"Niger", | |
"Nigeria", | |
"Norway", | |
"Oman", | |
"Pakistan", | |
"Palau", | |
"Panama", | |
"Papua New Guinea", | |
"Paraguay", | |
"Peru", | |
"Philippines", | |
"Poland", | |
"Portugal", | |
"Qatar", | |
"Romania", | |
"Russia", | |
"Rwanda", | |
"Saint Kitts and Nevis", | |
"Saint Lucia", | |
"Saint Vincent", | |
"Samoa", | |
"San Marino", | |
"Sao Tome and Principe", | |
"Saudi Arabia", | |
"Senegal", | |
"Serbia and Montenegro", | |
"Seychelles", | |
"Sierra Leone", | |
"Singapore", | |
"Slovakia", | |
"Slovenia", | |
"Solomon Islands", | |
"Somalia", | |
"South Africa", | |
"Spain", | |
"Sri Lanka", | |
"Sudan", | |
"Suriname", | |
"Swaziland", | |
"Sweden", | |
"Switzerland", | |
"Syria", | |
"Taiwan", | |
"Tajikistan", | |
"Tanzania", | |
"Thailand", | |
"Togo", | |
"Tonga", | |
"Trinidad and Tobago", | |
"Tunisia", | |
"Turkey", | |
"Turkmenistan", | |
"Tuvalu", | |
"Uganda", | |
"Ukraine", | |
"United Arab Emirates", | |
"United Kingdom", | |
"United States", | |
"Uruguay", | |
"Uzbekistan", | |
"Vanuatu", | |
"Vatican City", | |
"Venezuela", | |
"Vietnam", | |
"Yemen", | |
"Zambia", | |
"Zimbabwe" | |
); | |
if ($action == 'dropdown') { | |
foreach ($country_list as $country) { | |
echo "<option value=\"".$country."\""; | |
if (!empty($selectedid)) { | |
if ($selectedid == $country) { | |
echo " selected=\"selected\""; | |
} | |
} | |
echo ">".$country."</option>\n"; | |
} | |
} | |
elseif ($action == 'list') { | |
foreach ($country_list as $country) { | |
echo "<li>".$country."</li>\n"; | |
} | |
} | |
} | |
/********************* | |
Instruction: | |
$action = Type of Output (dropdown or list) | |
$selectedid = Selected option value (not needed) | |
Example 1: | |
<select name="country"> | |
<?php countrylist('dropdown','Albania') ?> | |
</select> | |
Output: | |
<select> | |
<option value="Afghanistan">Afghanistan</option> | |
<option value="Albania" selected="selected">Albania</option> | |
<option value="Algeria">Algeria</option> | |
<option................. | |
</select> | |
Example 2: | |
<ul> | |
<?php countrylist('list') ?> | |
</ul> | |
Output: | |
<ul> | |
<li>Afghanistan</li> | |
<li>Albania</li> | |
<li>Algeria</li> | |
<li................. | |
</ul> | |
************************/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment