網頁

2014年8月1日 星期五

PHP學習筆記-世上所有國家列表

最近正好寫php案子時有需要,查了一下,發現不少熱心的網友做好了,可以直接用,這邊將他們列出做點記錄,免得要用時,網頁蒸發了


$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",
  "Nepal",
  "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"
 );
With Country Code
$country_list = array(
    'Afghanistan' => '93',
    'Albania' => '355',
    'Algeria' => '213',
    'American Samoa' => '1 684',
    'Andorra' => '376',
    'Angola' => '244',
    'Anguilla' => '1264',
    'Antarctica' => '672',
    'Antigua and Barbuda' => '1268',
    'Antilles, Netherlands' => '599',
    'Argentina' => '54',
    'Armenia' => '374',
    'Aruba' => '297',
    'Australia' => '61',
    'Austria' => '43',
    'Azerbaijan' => '994',
    'Bahamas' => '1242',
    'Bahrain' => '973',
    'Bangladesh' => '880',
    'Barbados' => '1246',
    'Belarus' => '375',
    'Belgium' => '375',
    'Belize' => '501',
    'Benin' => '229',
    'Bermuda' => '1 441',
    'Bhutan' => '975',
    'Bolivia' => '591',
    'Bosnia and Herzegovina' => '387',
    'Botswana' => '267',
    'Brazil' => '55',
    'British Indian Ocean Territory' => '246',
    'British Virgin Islands' => '1 284',
    'Brunei Darussalam' => '673',
    'Bulgaria' => '359',
    'Burkina Faso' => '226',
    'Burundi' => '257',
    'Cambodia' => '855',
    'Cameroon' => '237',
    'Canada' => '1',
    'Cape Verde' => '238',
    'Cayman Islands' => '1 345',
    'Central African Republic' => '236',
    'Chad' => '235',
    'Chile' => '56',
    'China' => '86',
    'Christmas Island' => '64',
    'Cocos (Keeling) Islands' => '61',
    'Colombia' => '57',
    'Comoros' => '269',
    'Congo' => '242',
    'Cook Islands' => '682',
    'Costa Rica' => '506',
    'Cote D\'Ivoire' => '225',
    'Croatia' => '385',
    'Cuba' => '53',
    'Cyprus' => '357',
    'Czech Republic' => '420',
    'Denmark' => '45',
    'Djibouti' => '253',
    'Dominica' => '1 767',
    'Dominican Republic' => '1 809',
    'East Timor (Timor-Leste)' => '670',
    'Ecuador' => '593',
    'Egypt' => '20',
    'El Salvador' => '503',
    'Equatorial Guinea' => '240',
    'Eritrea' => '291',
    'Estonia' => '372',
    'Ethiopia' => '251',
    'Falkland Islands (Malvinas)' => '500',
    'Faroe Islands' => '298',
    'Fiji' => '679',
    'Finland' => '358',
    'France' => '33',
    'French Guiana' => '594',
    'French Polynesia' => '689',
    'Gabon' => '241',
    'Gambia, the' => '220',
    'Georgia' => '995',
    'Germany' => '49',
    'Ghana' => '233',
    'Gibraltar' => '350',
    'Greece' => '30',
    'Greenland' => '299',
    'Grenada' => '1 473',
    'Guadeloupe' => '590',
    'Guam' => '1 671',
    'Guatemala' => '502',
    'Guernsey and Alderney' => '5399',
    'Guinea' => '224',
    'Guinea-Bissau' => '245',
    'Guinea, Equatorial' => '240',
    'Guiana, French' => '594',
    'Guyana' => '592',
    'Haiti' => '509',
    'Holy See (Vatican City State)' => '379',
    'Holland' => '31',
    'Honduras' => '504',
    'Hong Kong, (China)' => '852',
    'Hungary' => '36',
    'Iceland' => '354',
    'India' => '91',
    'Indonesia' => '62',
    'Iran' => '98',
    'Iraq' => '964',
    'Ireland' => '353',
    'Isle of Man' => '44',
    'Israel' => '972',
    'Italy' => '39',
    'Jamaica' => '1 876',
    'Japan' => '81',
    'Jersey' => '44',
    'Jordan' => '962',
    'Kazakhstan' => '7',
    'Kenya' => '254',
    'Kiribati' => '686',
    'Korea(North)' => '850',
    'Korea(South)' => '82',
    'Kosovo' => '381',
    'Kuwait' => '965',
    'Kyrgyzstan' => '996',
    'Lao People\'s Democratic Republic' => '856',
    'Latvia' => '371',
    'Lebanon' => '961',
    'Lesotho' => '266',
    'Liberia' => '231',
    'Libyan Arab Jamahiriya' => '218',
    'Liechtenstein' => '423',
    'Lithuania' => '370',
    'Luxembourg' => '352',
    'Macao, (China)' => '853',
    'Macedonia, TFYR' => '389',
    'Madagascar' => '261',
    'Malawi' => '265',
    'Malaysia' => '60',
    'Maldives' => '960',
    'Mali' => '223',
    'Malta' => '356',
    'Marshall Islands' => '692',
    'Martinique' => '596',
    'Mauritania' => '222',
    'Mauritius' => '230',
    'Mayotte' => '262',
    'Mexico' => '52',
    'Micronesia' => '691',
    'Moldova' => '373',
    'Monaco' => '377',
    'Mongolia' => '976',
    'Montenegro' => '382',
    'Montserrat' => '1 664',
    'Morocco' => '212',
    'Mozambique' => '258',
    'Myanmar' => '95',
    'Namibia' => '264',
    'Nauru' => '674',
    'Nepal' => '977',
    'Netherlands' => '31',
    'Netherlands Antilles' => '599',
    'New Caledonia' => '687',
    'New Zealand' => '64',
    'Nicaragua' => '505',
    'Niger' => '227',
    'Nigeria' => '234',
    'Niue' => '683',
    'Norfolk Island' => '672',
    'Northern Mariana Islands' => '1 670',
    'Norway' => '47',
    'Oman' => '968',
    'Pakistan' => '92',
    'Palau' => '680',
    'Palestinian Territory' => '970',
    'Panama' => '507',
    'Papua New Guinea' => '675',
    'Paraguay' => '595',
    'Peru' => '51',
    'Philippines' => '63',
    'Pitcairn Island' => '872',
    'Poland' => '48',
    'Portugal' => '351',
    'Puerto Rico' => '1787',
    'Qatar' => '974',
    'Reunion' => '262',
    'Romania' => '40',
    'Russia' => '7',
    'Rwanda' => '250',
    'Sahara' => '212',
    'Saint Helena' => '290',
    'Saint Kitts and Nevis' => '1869',
    'Saint Lucia' => '1758',
    'Saint Pierre and Miquelon' => '508',
    'Saint Vincent and the Grenadines' => '1784',
    'Samoa' => '685',
    'San Marino' => '374',
    'Sao Tome and Principe' => '239',
    'Saudi Arabia' => '966',
    'Senegal' => '221',
    'Serbia' => '381',
    'Seychelles' => '248',
    'Sierra Leone' => '232',
    'Singapore' => '65',
    'Slovakia' => '421',
    'Slovenia' => '386',
    'Solomon Islands' => '677',
    'Somalia' => '252',
    'South Africa' => '27',
    'S. Georgia and S. Sandwich Is.' => '500',
    'Spain' => '34',
    'Sri Lanka (ex-Ceilan)' => '94',
    'Sudan' => '249',
    'Suriname' => '597',
    'Svalbard and Jan Mayen Islands' => '79',
    'Swaziland' => '41',
    'Sweden' => '46',
    'Switzerland' => '41',
    'Syrian Arab Republic' => '963',
    'Taiwan' => '886',
    'Tajikistan' => '992',
    'Tanzania' => '255',
    'Thailand' => '66',
    'Timor-Leste (East Timor)' => '670',
    'Togo' => '228',
    'Tokelau' => '690',
    'Tonga' => '676',
    'Trinidad and Tobago' => '1 868',
    'Tunisia' => '216',
    'Turkey' => '90',
    'Turkmenistan' => '993',
    'Turks and Caicos Islands' => '1 649',
    'Tuvalu' => '688',
    'Uganda' => '256',
    'Ukraine' => '380',
    'United Arab Emirates' => '971',
    'United Kingdom' => '44',
    'United States' => '1',
    'US Minor Outlying Islands' => '808',
    'Uruguay' => '598',
    'Uzbekistan' => '998',
    'Vanuatu' => '678',
    'Vatican City State (Holy See)' => '379',
    'Venezuela' => '58',
    'Viet Nam' => '84',
    'Virgin Islands, British' => '1284',
    'Virgin Islands, U.S.' => '1340',
    'Wallis and Futuna' => '681',
    'Western Sahara' => '212',
    'Yemen' => '967',
    'Zambia' => '260',
    'Zimbabwe' => '263',
);
有人基於上頭的資訊,做成底下的function:
/**
     * Returns array with country codes
     * @param stirng $zone Country zone, optional
     * @param stirng $code Specific country code (to get country name), optional
     * @return array Where keys are country codes and values are country names in english
     */
    function countryCodeArray($zone = 'all', $code = '')
    {
        $returnData = false;
        $country_array = array(
            'Africa' => array('DZ' => 'Algeria', 'AO' => 'Angola', 'BJ' => 'Benin', 'BW' => 'Botswana', 'BF' => 'Burkina Faso', 'BI' => 'Burundi', 'CM' => 'Cameroon', 'CV' => 'Cape Verde', 'CF' => 'Central African Republic', 'TD' => 'Chad', 'KM' => 'Comoros', 'CD' => 'Congo [DRC]', 'CG' => 'Congo [Republic]', 'DJ' => 'Djibouti', 'EG' => 'Egypt', 'GQ' => 'Equatorial Guinea', 'ER' => 'Eritrea', 'ET' => 'Ethiopia', 'GA' => 'Gabon', 'GM' => 'Gambia', 'GH' => 'Ghana', 'GN' => 'Guinea', 'GW' => 'Guinea-Bissau', 'CI' => 'Ivory Coast', 'KE' => 'Kenya', 'LS' => 'Lesotho', 'LR' => 'Liberia', 'LY' => 'Libya', 'MG' => 'Madagascar', 'MW' => 'Malawi', 'ML' => 'Mali', 'MR' => 'Mauritania', 'MU' => 'Mauritius', 'YT' => 'Mayotte', 'MA' => 'Morocco', 'MZ' => 'Mozambique', 'NA' => 'Namibia', 'NE' => 'Niger', 'NG' => 'Nigeria', 'RW' => 'Rwanda', 'RE' => 'Réunion', 'SH' => 'Saint Helena', 'SN' => 'Senegal', 'SC' => 'Seychelles', 'SL' => 'Sierra Leone', 'SO' => 'Somalia', 'ZA' => 'South Africa', 'SD' => 'Sudan', 'SZ' => 'Swaziland', 'ST' => 'São Tomé and Pr?ncipe', 'TZ' => 'Tanzania', 'TG' => 'Togo', 'TN' => 'Tunisia', 'UG' => 'Uganda', 'EH' => 'Western Sahara', 'ZM' => 'Zambia', 'ZW' => 'Zimbabwe'),
            'Antarctica' => array('AQ' => 'Antarctica', 'BV' => 'Bouvet Island', 'TF' => 'French Southern Territories', 'HM' => 'Heard Island and McDonald Island', 'GS' => 'South Georgia and the South Sandwich Islands'),
            'Asia' => array('AF' => 'Afghanistan', 'AM' => 'Armenia', 'AZ' => 'Azerbaijan', 'BH' => 'Bahrain', 'BD' => 'Bangladesh', 'BT' => 'Bhutan', 'IO' => 'British Indian Ocean Territory', 'BN' => 'Brunei', 'KH' => 'Cambodia', 'CN' => 'China', 'CX' => 'Christmas Island', 'CC' => 'Cocos [Keeling] Islands', 'GE' => 'Georgia', 'HK' => 'Hong Kong', 'IN' => 'India', 'ID' => 'Indonesia', 'IR' => 'Iran', 'IQ' => 'Iraq', 'IL' => 'Israel', 'JP' => 'Japan', 'JO' => 'Jordan', 'KZ' => 'Kazakhstan', 'KW' => 'Kuwait', 'KG' => 'Kyrgyzstan', 'LA' => 'Laos', 'LB' => 'Lebanon', 'MO' => 'Macau', 'MY' => 'Malaysia', 'MV' => 'Maldives', 'MN' => 'Mongolia', 'MM' => 'Myanmar [Burma]', 'NP' => 'Nepal', 'KP' => 'North Korea', 'OM' => 'Oman', 'PK' => 'Pakistan', 'PS' => 'Palestinian Territories', 'PH' => 'Philippines', 'QA' => 'Qatar', 'SA' => 'Saudi Arabia', 'SG' => 'Singapore', 'KR' => 'South Korea', 'LK' => 'Sri Lanka', 'SY' => 'Syria', 'TW' => 'Taiwan', 'TJ' => 'Tajikistan', 'TH' => 'Thailand', 'TR' => 'Turkey', 'TM' => 'Turkmenistan', 'AE' => 'United Arab Emirates', 'UZ' => 'Uzbekistan', 'VN' => 'Vietnam', 'YE' => 'Yemen'),
            'Europe' => array('AL' => 'Albania', 'AD' => 'Andorra', 'AT' => 'Austria', 'BY' => 'Belarus', 'BE' => 'Belgium', 'BA' => 'Bosnia and Herzegovina', 'BG' => 'Bulgaria', 'HR' => 'Croatia', 'CY' => 'Cyprus', 'CZ' => 'Czech Republic', 'DK' => 'Denmark', 'EE' => 'Estonia', 'FO' => 'Faroe Islands', 'FI' => 'Finland', 'FR' => 'France', 'DE' => 'Germany', 'GI' => 'Gibraltar', 'GR' => 'Greece', 'GG' => 'Guernsey', 'HU' => 'Hungary', 'IS' => 'Iceland', 'IE' => 'Ireland', 'IM' => 'Isle of Man', 'IT' => 'Italy', 'JE' => 'Jersey', 'XK' => 'Kosovo', 'LV' => 'Latvia', 'LI' => 'Liechtenstein', 'LT' => 'Lithuania', 'LU' => 'Luxembourg', 'MK' => 'Macedonia', 'MT' => 'Malta', 'MD' => 'Moldova', 'MC' => 'Monaco', 'ME' => 'Montenegro', 'NL' => 'Netherlands', 'NO' => 'Norway', 'PL' => 'Poland', 'PT' => 'Portugal', 'RO' => 'Romania', 'RU' => 'Russia', 'SM' => 'San Marino', 'RS' => 'Serbia', 'CS' => 'Serbia and Montenegro', 'SK' => 'Slovakia', 'SI' => 'Slovenia', 'ES' => 'Spain', 'SJ' => 'Svalbard and Jan Mayen', 'SE' => 'Sweden', 'CH' => 'Switzerland', 'UA' => 'Ukraine', 'GB' => 'United Kingdom', 'VA' => 'Vatican City', 'AX' => 'Åland Islands'),
            'North America' => array('AI' => 'Anguilla', 'AG' => 'Antigua and Barbuda', 'AW' => 'Aruba', 'BS' => 'Bahamas', 'BB' => 'Barbados', 'BZ' => 'Belize', 'BM' => 'Bermuda', 'BQ' => 'Bonaire, Saint Eustatius and Saba', 'VG' => 'British Virgin Islands', 'CA' => 'Canada', 'KY' => 'Cayman Islands', 'CR' => 'Costa Rica', 'CU' => 'Cuba', 'CW' => 'Curacao', 'DM' => 'Dominica', 'DO' => 'Dominican Republic', 'SV' => 'El Salvador', 'GL' => 'Greenland', 'GD' => 'Grenada', 'GP' => 'Guadeloupe', 'GT' => 'Guatemala', 'HT' => 'Haiti', 'HN' => 'Honduras', 'JM' => 'Jamaica', 'MQ' => 'Martinique', 'MX' => 'Mexico', 'MS' => 'Montserrat', 'AN' => 'Netherlands Antilles', 'NI' => 'Nicaragua', 'PA' => 'Panama', 'PR' => 'Puerto Rico', 'BL' => 'Saint Barthélemy', 'KN' => 'Saint Kitts and Nevis', 'LC' => 'Saint Lucia', 'MF' => 'Saint Martin', 'PM' => 'Saint Pierre and Miquelon', 'VC' => 'Saint Vincent and the Grenadines', 'SX' => 'Sint Maarten', 'TT' => 'Trinidad and Tobago', 'TC' => 'Turks and Caicos Islands', 'VI' => 'U.S. Virgin Islands', 'US' => 'United States'),
            'South America' => array('AR' => 'Argentina', 'BO' => 'Bolivia', 'BR' => 'Brazil', 'CL' => 'Chile', 'CO' => 'Colombia', 'EC' => 'Ecuador', 'FK' => 'Falkland Islands', 'GF' => 'French Guiana', 'GY' => 'Guyana', 'PY' => 'Paraguay', 'PE' => 'Peru', 'SR' => 'Suriname', 'UY' => 'Uruguay', 'VE' => 'Venezuela'),
            'Oceania' => array('AS' => 'American Samoa', 'AU' => 'Australia', 'CK' => 'Cook Islands', 'TL' => 'East Timor', 'FJ' => 'Fiji', 'PF' => 'French Polynesia', 'GU' => 'Guam', 'KI' => 'Kiribati', 'MH' => 'Marshall Islands', 'FM' => 'Micronesia', 'NR' => 'Nauru', 'NC' => 'New Caledonia', 'NZ' => 'New Zealand', 'NU' => 'Niue', 'NF' => 'Norfolk Island', 'MP' => 'Northern Mariana Islands', 'PW' => 'Palau', 'PG' => 'Papua New Guinea', 'PN' => 'Pitcairn Islands', 'WS' => 'Samoa', 'SB' => 'Solomon Islands', 'TK' => 'Tokelau', 'TO' => 'Tonga', 'TV' => 'Tuvalu', 'UM' => 'U.S. Minor Outlying Islands', 'VU' => 'Vanuatu', 'WF' => 'Wallis and Futuna')
        );
        if ($zone == 'all') {
            $returnData = $country_array;
        } elseif (isset($country_array[$zone])) {
            if ($code != '') {
                if (isset($country_array[$zone][$code])) {
                    $returnData = $country_array[$zone][$code];
                }
            } else {
                $returnData = $country_array[$zone];
            }
        }
        return $returnData;
    }


也許寫個像Create your own countries list的工具倒是。

參考網址:
List of world countries in php array
Text List of All Countries in the World
Javascript - All countries of the world in an array
Create your own countries list

沒有留言:

張貼留言