7
A
回答
24
PHP本身沒有這些值的知識。你必須創建自己的代碼:
方法1:
創建這樣一個數組:
$COUNTRY = array(
"Australia" => "AU",
"Germany" => "GER"
...
);
之後,只需使用pre0stored值:
echo $COUNTRY['Australia'];
方法2(建議):
個存儲值到DB:
+-----------+------+
| Country | Code |
+-----------+------+
| Australia | AU |
| Germany | GER |
...
+-----------+------+
而且具有簡單的查詢訪問:
SELECT Code FROM country_db WHERE Country = 'Australia';
編輯
CREATE TABLE
country_code
(
code,
country
);
INSERT INTO
country_code
(code, country)
VALUES
('AF', 'Afghanistan'),
('AX', 'Aland Islands'),
('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 (Bouvetoya)'),
('BR', 'Brazil'),
('IO', 'British Indian Ocean Territory (Chagos Archipelago)'),
('VG', 'British Virgin Islands'),
('BN', 'Brunei Darussalam'),
('BG', 'Bulgaria'),
('BF', 'Burkina Faso'),
('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 the'),
('CD', 'Congo'),
('CG', 'Congo the'),
('CK', 'Cook Islands'),
('CR', 'Costa Rica'),
('CI', 'Cote d\'Ivoire'),
('HR', 'Croatia'),
('CU', 'Cuba'),
('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'),
('FO', 'Faroe Islands'),
('FK', 'Falkland Islands (Malvinas)'),
('FJ', 'Fiji the Fiji Islands'),
('FI', 'Finland'),
('FR', 'France, French Republic'),
('GF', 'French Guiana'),
('PF', 'French Polynesia'),
('TF', 'French Southern Territories'),
('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'),
('VA', 'Holy See (Vatican City State)'),
('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'),
('KR', 'Korea'),
('KW', 'Kuwait'),
('KG', 'Kyrgyz Republic'),
('LA', 'Lao'),
('LV', 'Latvia'),
('LB', 'Lebanon'),
('LS', 'Lesotho'),
('LR', 'Liberia'),
('LY', 'Libyan Arab Jamahiriya'),
('LI', 'Liechtenstein'),
('LT', 'Lithuania'),
('LU', 'Luxembourg'),
('MO', 'Macao'),
('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'),
('MD', 'Moldova'),
('MC', 'Monaco'),
('MN', 'Mongolia'),
('ME', 'Montenegro'),
('MS', 'Montserrat'),
('MA', 'Morocco'),
('MZ', 'Mozambique'),
('MM', 'Myanmar'),
('NA', 'Namibia'),
('NR', 'Nauru'),
('NP', 'Nepal'),
('AN', 'Netherlands Antilles'),
('NL', 'Netherlands the'),
('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'),
('PS', 'Palestinian Territory'),
('PA', 'Panama'),
('PG', 'Papua New Guinea'),
('PY', 'Paraguay'),
('PE', 'Peru'),
('PH', 'Philippines'),
('PN', 'Pitcairn Islands'),
('PL', 'Poland'),
('PT', 'Portugal, Portuguese Republic'),
('PR', 'Puerto Rico'),
('QA', 'Qatar'),
('RE', 'Reunion'),
('RO', 'Romania'),
('RU', 'Russian Federation'),
('RW', 'Rwanda'),
('BL', 'Saint Barthelemy'),
('SH', 'Saint Helena'),
('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'),
('SK', 'Slovakia (Slovak Republic)'),
('SI', 'Slovenia'),
('SB', 'Solomon Islands'),
('SO', 'Somalia, Somali Republic'),
('ZA', 'South Africa'),
('GS', 'South Georgia and the South Sandwich Islands'),
('ES', 'Spain'),
('LK', 'Sri Lanka'),
('SD', 'Sudan'),
('SR', 'Suriname'),
('SJ', 'Svalbard & Jan Mayen Islands'),
('SZ', 'Swaziland'),
('SE', 'Sweden'),
('CH', 'Switzerland, Swiss Confederation'),
('SY', 'Syrian Arab Republic'),
('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 of America'),
('UM', 'United States Minor Outlying Islands'),
('VI', 'United States Virgin Islands'),
('UY', 'Uruguay, Eastern Republic of'),
('UZ', 'Uzbekistan'),
('VU', 'Vanuatu'),
('VE', 'Venezuela'),
('VN', 'Vietnam'),
('WF', 'Wallis and Futuna'),
('EH', 'Western Sahara'),
('YE', 'Yemen'),
('ZM', 'Zambia'),
('ZW', 'Zimbabwe');
+22
在這裏,你懶惰......拿走了我3分鐘...... – Peon
+5
哈哈:爲你的努力+1);) –
相關問題
- 1. 轉換國家代碼國家名稱
- 2. 將國家代碼轉換爲國家名稱
- 3. 如何將國家代碼轉換爲國家名稱
- 4. 國家代碼到國家/地區名稱轉換
- 5. 將國家名稱更改爲縮寫
- 6. pycountries:將國家/地區名稱(可能不完整!)轉換爲國家代碼
- 7. 轉換ISO2國家代碼
- 8. 如何將國家名稱轉換爲貨幣代碼?
- 9. 將ISO3國家代碼轉換爲ISO2國家代碼 - Windows Phone 8
- 10. PHP國際國家代碼2國家代碼的字符
- 11. 國家名稱爲ISO 3166-2代碼
- 12. 將電話號碼轉換爲國際國家代碼iOS
- 13. 如何使用php-intl將國家代碼轉換爲本地化的國家名稱
- 14. 從國家/地區代碼獲取國家/地區名稱
- 15. C#:從國家代碼獲取國家名稱
- 16. 從國家代碼在python中獲取國家名稱?
- 17. 從國家代碼中獲取國家/地區名稱
- 18. 在IOS中從國家名稱獲取國家代碼
- 19. 國家和國家撥號代碼,國家名稱和國家圖標目標c
- 20. 選擇國家和國家代碼?
- 21. 如何用R中的國家代碼包將英文中的國家名稱轉換爲法語?
- 22. 在excel中將三個字母的國家/地區代碼轉換爲完整的國家/地區名稱
- 23. Csv國家代碼/名稱列表?
- 24. 如何國家代碼轉換成國名
- 25. Magento:按國名獲取國家代碼
- 26. Android Locale國名到國家代碼
- 27. 在.NET中轉換國家代碼
- 28. 獲取給定電話號碼的詳細國家名稱和國家代碼
- 29. 使用Javascript - 填寫國家代碼下拉國家下拉
- 30. IOS:國家代碼
我不這麼認爲。我也會那樣做它在我自己 –
在您的數據庫中創建一個表,將全名映射到縮寫,然後轉換。或者你可以使用一個數組,但這可能很乏味。 – Matt
但是,多於239個國家,那是太多的編碼,必須有辦法做到這一點 – user1299846