5

我正在按国家/地区名称显示时区列表。

如此处回答: PHP/Zend 框架中的国家到时区

我想打电话DateTimeZone::listIdentifiers(DateTimeZone::PER_COUNTRY, 'US')按国家列出所有时区。

有没有简单的方法来获取 ISO 3166-1 兼容的国家代码列表及其在 PHP(PHP 5.3)中的相应名称?

4

5 回答 5

7

我刚刚从 Riccardo Zorn 提到的链接中编制了一份清单。

$country_name_to_code = array(
    'AFGHANISTAN' => 'AF',
    // 'AKROTIRI' => '*',
    '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',
    // 'ASHMORE AND CARTIER ISLANDS' => '*',
    'AUSTRALIA' => 'AU',
    'AUSTRIA' => 'AT',
    'AZERBAIJAN' => 'AZ',
    'BAHAMAS, THE' => 'BS',
    'BAHRAIN' => 'BH',
    // 'BAKER ISLAND' => '*',
    'BANGLADESH' => 'BD',
    'BARBADOS' => 'BB',
    // 'BASSAS DA INDIA' => '*',
    'BELARUS' => 'BY',
    'BELGIUM' => 'BE',
    'BELIZE' => 'BZ',
    'BENIN' => 'BJ',
    'BERMUDA' => 'BM',
    'BHUTAN' => 'BT',
    'BOLIVIA' => 'BO',
    'BOSNIA AND HERZEGOVINA' => 'BA',
    'BOTSWANA' => 'BW',
    'BOUVET ISLAND' => 'BV',
    'BRAZIL' => 'BR',
    'BRITISH INDIAN OCEAN TERRITORY' => 'IO',
    'BRUNEI' => 'BN',
    'BULGARIA' => 'BG',
    'BURKINA FASO' => 'BF',
    'BURMA' => 'MM',
    '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',
    // 'CLIPPERTON ISLAND' => '*',
    'COCOS (KEELING) ISLANDS' => 'CC',
    'COLOMBIA' => 'CO',
    'COMOROS' => 'KM',
    'CONGO (BRAZZAVILLE) ' => 'CG',
    'CONGO (KINSHASA)' => 'CD',
    'COOK ISLANDS' => 'CK',
    // 'CORAL SEA ISLANDS' => '*',
    'COSTA RICA' => 'CR',
    'CÔTE D’IVOIRE' => 'CI',
    'CROATIA' => 'HR',
    'CUBA' => 'CU',
    'CURAÇAO' => 'CW',
    'CYPRUS' => 'CY',
    'CZECH REPUBLIC' => 'CZ',
    'DENMARK' => 'DK',
    // 'DHEKELIA' => '*',
    'DJIBOUTI' => 'DJ',
    'DOMINICA' => 'DM',
    'DOMINICAN REPUBLIC' => 'DO',
    'ECUADOR' => 'EC',
    'EGYPT' => 'EG',
    'EL SALVADOR' => 'SV',
    'EQUATORIAL GUINEA' => 'GQ',
    'ERITREA' => 'ER',
    'ESTONIA' => 'EE',
    'ETHIOPIA' => 'ET',
    // 'ETOROFU, HABOMAI, KUNASHIRI, AND SHIKOTAN ISLANDS' => '*',
    // 'EUROPA ISLAND' => '*',
    'FALKLAND ISLANDS (ISLAS MALVINAS)' => 'FK',
    'FAROE ISLANDS' => 'FO',
    'FIJI' => 'FJ',
    'FINLAND' => 'FI',
    'FRANCE' => 'FR',
    'FRENCH GUIANA' => 'GF',
    'FRENCH POLYNESIA' => 'PF',
    'FRENCH SOUTHERN AND ANTARCTIC LANDS' => 'TF',
    'GABON' => 'GA',
    'GAMBIA, THE' => 'GM',
    // 'GAZA STRIP' => '*',
    'GEORGIA' => 'GE',
    'GERMANY' => 'DE',
    'GHANA' => 'GH',
    'GIBRALTAR' => 'GI',
    // 'GLORIOSO ISLANDS' => '*',
    'GREECE' => 'GR',
    'GREENLAND' => 'GL',
    'GRENADA' => 'GD',
    'GUADELOUPE' => 'GP',
    'GUAM' => 'GU',
    'GUATEMALA' => 'GT',
    'GUERNSEY' => 'GG',
    'GUINEA' => 'GN',
    'GUINEA-BISSAU' => 'GW',
    'GUYANA' => 'GY',
    'HAITI' => 'HT',
    'HEARD ISLAND AND MCDONALD ISLANDS' => 'HM',
    'HONDURAS' => 'HN',
    'HONG KONG' => 'HK',
    // 'HOWLAND ISLAND' => '*',
    'HUNGARY' => 'HU',
    'ICELAND' => 'IS',
    'INDIA' => 'IN',
    'INDONESIA' => 'ID',
    'IRAN' => 'IR',
    'IRAQ' => 'IQ',
    'IRELAND' => 'IE',
    'ISLE OF MAN' => 'IM',
    'ISRAEL' => 'IL',
    'ITALY' => 'IT',
    'JAMAICA' => 'JM',
    // 'JAN MAYEN' => '*',
    'JAPAN' => 'JP',
    // 'JARVIS ISLAND' => '*',
    'JERSEY' => 'JE',
    // 'JOHNSTON ATOLL' => '*',
    'JORDAN' => 'JO',
    // 'JUAN DE NOVA ISLAND' => '*',
    'KAZAKHSTAN' => 'KZ',
    'KENYA' => 'KE',
    // 'KINGMAN REEF' => '*',
    'KIRIBATI' => 'KI',
    'KOREA, NORTH' => 'KP',
    'KOREA, SOUTH' => 'KR',
    // 'KOSOVO' => '*',
    'KUWAIT' => 'KW',
    'KYRGYZSTAN' => 'KG',
    'LAOS' => 'LA',
    'LATVIA' => 'LV',
    'LEBANON' => 'LB',
    'LESOTHO' => 'LS',
    'LIBERIA' => 'LR',
    'LIBYA' => 'LY',
    'LIECHTENSTEIN' => 'LI',
    'LITHUANIA' => 'LT',
    'LUXEMBOURG' => 'LU',
    'MACAU' => '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, FEDERATED STATES OF' => 'FM',
    // 'MIDWAY ISLANDS' => '*',
    'MOLDOVA' => 'MD',
    'MONACO' => 'MC',
    'MONGOLIA' => 'MN',
    'MONTENEGRO' => 'ME',
    'MONTSERRAT' => 'MS',
    'MOROCCO' => 'MA',
    'MOZAMBIQUE' => 'MZ',
    'NAMIBIA' => 'NA',
    'NAURU' => 'NR',
    // 'NAVASSA ISLAND' => '*',
    'NEPAL' => 'NP',
    'NETHERLANDS' => 'NL',
    'NEW CALEDONIA' => 'NC',
    'NEW ZEALAND' => 'NZ',
    'NICARAGUA' => 'NI',
    'NIGER' => 'NE',
    'NIGERIA' => 'NG',
    'NIUE' => 'NU',
    'NORFOLK ISLAND' => 'NF',
    'NORTHERN MARIANA ISLANDS' => 'MP',
    'NORWAY' => 'NO',
    'OMAN' => 'OM',
    'PAKISTAN' => 'PK',
    'PALAU' => 'PW',
    // 'PALMYRA ATOLL' => '*',
    'PANAMA' => 'PA',
    'PAPUA NEW GUINEA' => 'PG',
    // 'PARACEL ISLANDS' => '*',
    'PARAGUAY' => 'PY',
    'PERU' => 'PE',
    'PHILIPPINES' => 'PH',
    'PITCAIRN ISLANDS' => 'PN',
    'POLAND' => 'PL',
    'PORTUGAL' => 'PT',
    'PUERTO RICO' => 'PR',
    'QATAR' => 'QA',
    'REUNION' => 'RE',
    'ROMANIA' => 'RO',
    'RUSSIA' => 'RU',
    'RWANDA' => 'RW',
    'SAINT BARTHELEMY' => 'BL',
    'SAINT HELENA, ASCENSION, AND TRISTAN DA CUNHA' => 'SH',
    'SAINT KITTS AND NEVIS' => 'KN',
    'SAINT LUCIA' => 'LC',
    'SAINT MARTIN' => 'MF',
    'SAINT PIERRE AND MIQUELON' => 'PM',
    'SAINT VINCENT AND THE GRENADINES' => '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' => 'SX',
    'SLOVAKIA' => 'SK',
    'SLOVENIA' => 'SI',
    'SOLOMON ISLANDS' => 'SB',
    'SOMALIA' => 'SO',
    'SOUTH AFRICA' => 'ZA',
    'SOUTH GEORGIA AND SOUTH SANDWICH ISLANDS' => 'GS',
    'SOUTH SUDAN' => 'SS',
    'SPAIN' => 'ES',
    // 'SPRATLY ISLANDS' => '*',
    'SRI LANKA' => 'LK',
    'SUDAN' => 'SD',
    'SURINAME' => 'SR',
    // 'SVALBARD' => '*',
    'SWAZILAND' => 'SZ',
    'SWEDEN' => 'SE',
    'SWITZERLAND' => 'CH',
    'SYRIA' => 'SY',
    'TAIWAN' => 'TW',
    'TAJIKISTAN' => 'TJ',
    'TANZANIA' => 'TZ',
    'THAILAND' => 'TH',
    'TIMOR-LESTE' => 'TL',
    'TOGO' => 'TG',
    'TOKELAU' => 'TK',
    'TONGA' => 'TO',
    'TRINIDAD AND TOBAGO' => 'TT',
    // 'TROMELIN ISLAND' => '*',
    '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',
    'VATICAN CITY' => 'VA',
    'VENEZUELA' => 'VE',
    'VIETNAM' => 'VN',
    'VIRGIN ISLANDS, BRITISH' => 'VG',
    'VIRGIN ISLANDS, UNITED STATES ' => 'VI',
    // 'WAKE ISLAND' => '*',
    'WALLIS AND FUTUNA' => 'WF',
    // 'WEST BANK' => '*',
    'WESTERN SAHARA' => 'EH',
    'YEMEN' => 'YE',
    'ZAMBIA' => 'ZM',
    'ZIMBABWE' => 'ZW');

$country_code_to_name = array(
    'AF' => 'Afghanistan',
    '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, The',
    'BH' => 'Bahrain',
    'BD' => 'Bangladesh',
    'BB' => 'Barbados',
    'BY' => 'Belarus',
    'BE' => 'Belgium',
    'BZ' => 'Belize',
    'BJ' => 'Benin',
    'BM' => 'Bermuda',
    'BT' => 'Bhutan',
    'BO' => 'Bolivia',
    'BA' => 'Bosnia And Herzegovina',
    'BW' => 'Botswana',
    'BV' => 'Bouvet Island',
    'BR' => 'Brazil',
    'IO' => 'British Indian Ocean Territory',
    'BN' => 'Brunei',
    'BG' => 'Bulgaria',
    'BF' => 'Burkina Faso',
    'MM' => 'Burma',
    '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 (brazzaville) ',
    'CD' => 'Congo (kinshasa)',
    'CK' => 'Cook Islands',
    'CR' => 'Costa Rica',
    'CI' => 'CÔte D’ivoire',
    'HR' => 'Croatia',
    'CU' => 'Cuba',
    'CW' => 'CuraÇao',
    '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',
    'FK' => 'Falkland Islands (islas Malvinas)',
    'FO' => 'Faroe Islands',
    'FJ' => 'Fiji',
    'FI' => 'Finland',
    'FR' => 'France',
    'GF' => 'French Guiana',
    'PF' => 'French Polynesia',
    'TF' => 'French Southern And Antarctic Lands',
    'GA' => 'Gabon',
    'GM' => 'Gambia, The',
    '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',
    'HM' => 'Heard Island And Mcdonald Islands',
    '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, North',
    'KR' => 'Korea, South',
    'KW' => 'Kuwait',
    'KG' => 'Kyrgyzstan',
    'LA' => 'Laos',
    'LV' => 'Latvia',
    'LB' => 'Lebanon',
    'LS' => 'Lesotho',
    'LR' => 'Liberia',
    'LY' => 'Libya',
    'LI' => 'Liechtenstein',
    'LT' => 'Lithuania',
    'LU' => 'Luxembourg',
    'MO' => 'Macau',
    '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, Federated States Of',
    'MD' => 'Moldova',
    'MC' => 'Monaco',
    'MN' => 'Mongolia',
    'ME' => 'Montenegro',
    'MS' => 'Montserrat',
    'MA' => 'Morocco',
    'MZ' => 'Mozambique',
    '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' => 'Northern Mariana Islands',
    'NO' => 'Norway',
    'OM' => 'Oman',
    'PK' => 'Pakistan',
    'PW' => 'Palau',
    'PA' => 'Panama',
    'PG' => 'Papua New Guinea',
    'PY' => 'Paraguay',
    'PE' => 'Peru',
    'PH' => 'Philippines',
    'PN' => 'Pitcairn Islands',
    'PL' => 'Poland',
    'PT' => 'Portugal',
    'PR' => 'Puerto Rico',
    'QA' => 'Qatar',
    'RE' => 'Reunion',
    'RO' => 'Romania',
    'RU' => 'Russia',
    'RW' => 'Rwanda',
    'BL' => 'Saint Barthelemy',
    'SH' => 'Saint Helena, Ascension, And Tristan Da Cunha',
    'KN' => 'Saint Kitts And Nevis',
    'LC' => 'Saint Lucia',
    'MF' => 'Saint Martin',
    'PM' => 'Saint Pierre And Miquelon',
    'VC' => 'Saint Vincent And The Grenadines',
    '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',
    'SK' => 'Slovakia',
    'SI' => 'Slovenia',
    'SB' => 'Solomon Islands',
    'SO' => 'Somalia',
    'ZA' => 'South Africa',
    'GS' => 'South Georgia And South Sandwich Islands',
    'SS' => 'South Sudan',
    'ES' => 'Spain',
    'LK' => 'Sri Lanka',
    'SD' => 'Sudan',
    'SR' => 'Suriname',
    'SZ' => 'Swaziland',
    'SE' => 'Sweden',
    'CH' => 'Switzerland',
    'SY' => 'Syria',
    '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',
    'VA' => 'Vatican City',
    'VE' => 'Venezuela',
    'VN' => 'Vietnam',
    'VG' => 'Virgin Islands, British',
    'VI' => 'Virgin Islands, United States ',
    'WF' => 'Wallis And Futuna',
    'EH' => 'Western Sahara',
    'YE' => 'Yemen',
    'ZM' => 'Zambia',
    'ZW' => 'Zimbabwe');

它可能对其他人有用。

于 2013-01-30T13:34:39.050 回答
6

我已经维护https://github.com/thephpleague/iso3166很长一段时间了。没什么花哨的,只是提供它所宣传的内容:-)

较早的版本支持 PHP 5.3,但我最近放弃了它,因为它完全报废了。

于 2016-04-21T10:27:04.377 回答
4

您可以在http://country.io/names.json获得一个包含国家代码到名称的 JSON 文件,您可以使用该文件将国家代码转换为名称:

// Either download the JSON in your code like this,
// or just paste the contents into your code
$country_names = json_decode(
    file_get_contents("http://country.io/names.json")
, true);

function get_name($cc) {
    return $country_names[$cc];
}

get_name("GB"); // => "United Kingdom"
于 2014-09-05T02:09:54.830 回答
2

查看我能找到的最广泛和最新的列表:

http earth-info.nima.mil/gns/html/gazetteers2.html(旧链接见下文)

他们提供了一个 xls 下载,其中包含以下列:

FIPS      10-4  ISO 3166 digraph    ISO 3166 trigraph   ISO 3166 numeric    TLD IOC SOVEREIGNTY

(查看 xls 文件中的第 4 页)

2016 年更新:链接失效,试试这个: http: //geonames.nga.mil/gns/html/

于 2013-01-30T08:23:23.063 回答
0

官方来源似乎是最新的,并且有不同的 ISO 3166 代码可用:

迎合:

  • 阿尔法 2 代码
  • 阿尔法 3 代码
  • 数字

https://www.iso.org/obp/ui/#search/code/

于 2018-05-05T10:23:13.013 回答