Locale::getDisplayRegion() - Locale类
Locale::getDisplayRegion()
locale_get_display_region
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Returns an appropriately localized display name for region of the input locale
说明
面向对象风格publicstaticLocale::getDisplayRegion(string $locale[,string $in_locale]): string过程化风格
locale_get_display_region(string $locale[,string $in_locale]): string
Returns an appropriately localized display name for region of the input locale. If is NULL
then the default locale is used.
参数
$localeThe locale to return a display region for.
$in_localeOptional format locale to use to display the region name
返回值
display name of the region for the $locale in the format appropriate for $in_locale.
范例
locale_get_display_region() example
OO example
以上例程会输出:
Italy; Italie; Italien
参见
- locale_get_display_name() Returns an appropriately localized display name for the input locale
- locale_get_display_language() Returns an appropriately localized display name for language of the inputlocale
- locale_get_display_script() Returns an appropriately localized display name for script of the input locale
- locale_get_display_variant() Returns an appropriately localized display name for variants of the input locale
You don't have to have a fully-formed locale for the first parameter. This makes the function useful for getting the country name from any locale:
in fact , I would do exactly the opposite : find the country code (iso3166) from the country name. Found on the web, one solution is to use a table of correspondence between the country code and the country name for each language. There are too many countries and language code for this type of table. With a PHP function , the convertion can be performed as well: function countryNameToISO3166($country_name, $language) { if (strlen($language) != 2) { //Language must be on 2 caracters return NULL; } //Set uppercase if never $language = strtoupper($language); $countrycode_list = array('AF', 'AX', 'AL', 'DZ', 'AS', 'AD', 'AO', 'AI', 'AQ', 'AG', 'AR', 'AM', 'AW', 'AU', 'AT', 'AZ', 'BS', 'BH', 'BD', 'BB', 'BY', 'BE', 'BZ', 'BJ', 'BM', 'BT', 'BO', 'BQ', 'BA', 'BW', 'BV', 'BR', 'IO', 'BN', 'BG', 'BF', 'BI', 'KH', 'CM', 'CA', 'CV', 'KY', 'CF', 'TD', 'CL', 'CN', 'CX', 'CC', 'CO', 'KM', 'CG', 'CD', 'CK', 'CR', 'CI', 'HR', 'CU', 'CW', 'CY', 'CZ', 'DK', 'DJ', 'DM', 'DO', 'EC', 'EG', 'SV', 'GQ', 'ER', 'EE', 'ET', 'FK', 'FO', 'FJ', 'FI', 'FR', 'GF', 'PF', 'TF', 'GA', 'GM', 'GE', 'DE', 'GH', 'GI', 'GR', 'GL', 'GD', 'GP', 'GU', 'GT', 'GG', 'GN', 'GW', 'GY', 'HT', 'HM', 'VA', 'HN', 'HK', 'HU', 'IS', 'IN', 'ID', 'IR', 'IQ', 'IE', 'IM', 'IL', 'IT', 'JM', 'JP', 'JE', 'JO', 'KZ', 'KE', 'KI', 'KP', 'KR', 'KW', 'KG', 'LA', 'LV', 'LB', 'LS', 'LR', 'LY', 'LI', 'LT', 'LU', 'MO', 'MK', 'MG', 'MW', 'MY', 'MV', 'ML', 'MT', 'MH', 'MQ', 'MR', 'MU', 'YT', 'MX', 'FM', 'MD', 'MC', 'MN', 'ME', 'MS', 'MA', 'MZ', 'MM', 'NA', 'NR', 'NP', 'NL', 'NC', 'NZ', 'NI', 'NE', 'NG', 'NU', 'NF', 'MP', 'NO', 'OM', 'PK', 'PW', 'PS', 'PA', 'PG', 'PY', 'PE', 'PH', 'PN', 'PL', 'PT', 'PR', 'QA', 'RE', 'RO', 'RU', 'RW', 'BL', 'SH', 'KN', 'LC', 'MF', 'PM', 'VC', 'WS', 'SM', 'ST', 'SA', 'SN', 'RS', 'SC', 'SL', 'SG', 'SX', 'SK', 'SI', 'SB', 'SO', 'ZA', 'GS', 'SS', 'ES', 'LK', 'SD', 'SR', 'SJ', 'SZ', 'SE', 'CH', 'SY', 'TW', 'TJ', 'TZ', 'TH', 'TL', 'TG', 'TK', 'TO', 'TT', 'TN', 'TR', 'TM', 'TC', 'TV', 'UG', 'UA', 'AE', 'GB', 'US', 'UM', 'UY', 'UZ', 'VU', 'VE', 'VN', 'VG', 'VI', 'WF', 'EH', 'YE', 'ZM', 'ZW'); $ISO3166 = NULL; //Loop all country codes foreach ($countrycode_list as $countrycode) { $locale_cc = Locale::getDisplayRegion('-' . $countrycode, $language); //Case insensitive if (strcasecmp($country_name, $locale_cc) == 0) { $ISO3166 = $countrycode; break; } } //return NULL if not found or country code return $ISO3166; } Tests $cc=countryNameToISO3166('Costa Rica','US'); echo '
(English) Country code for Costa Rica is '.$cc; $cc=countryNameToISO3166('Royaume-Uni','FR'); echo '
(Français) Country code for Royaume-Uni is '.$cc; $cc=countryNameToISO3166('Frankreich','DE'); echo '
(Deutsch) Country code for Frankreich is '.$cc; //Wrong language $cc=countryNameToISO3166('Royaume-Uni','US'); echo '
(English) Country code for Royaume-Uni is '.var_dump($cc); returns (English) Country code for Costa Rica is CR (Français) Country code for Royaume-Uni is GB (Deutsch) Country code for Frankreich is FR (English) Country code for Royaume-Uni is NULL Hope it can help someone other http://www.fobec.com
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)