PHP intl国家/地区代码2字符为国家名称 [英] PHP intl country code 2 chars to country name

查看:53
本文介绍了PHP intl国家/地区代码2字符为国家名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用PHP将2个字符的国家代码(ISO 3166-1)转换为国家名称或国际国家代码,以便我可以翻译国家名称.

I'm triying to convert, using PHP, 2 characters country code (ISO 3166-1) to country names, or intl country codes, so I can translate the country name.

使用 Locale :: getDisplayRegion 需要语言的语言环境代码( nl_NL ),我所拥有的只是2个字符的国家/地区代码.我不想依靠Web服务,但是我可以考虑使用geoip扩展(无论如何我都找不到使用它的解决方案)

Using Locale::getDisplayRegion needs locale codes for languages (nl_NL) and all I have is the 2 characters country code. I don't want to rely on Webservices, but I can think on the geoip extension (I can't find a solution using it anyway)

有没有办法在不使用Web服务或外部资源的情况下获取2个字符的国家/地区代码并将其转换为PHP中的本地化国家名称?

Is there any way to get the 2 chars country code and convert it to localiced country name in PHP without using webservices or external resources?

(我之前使用过zend_locale,但是zf2没有该功能)

(I was using zend_locale some time ago, but zf2 does not have that functionality)

推荐答案

对于第一个参数,您不必具有完整的语言环境.这使该功能对于从任何语言环境中获取国家/地区名称非常有用:

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:

<?php
var_dump(Locale::getDisplayRegion('-US', 'fr'));

//Returns
string 'États-Unis' (length=11)
?>

http://php.net/manual/en/locale.getdisplayregion.php#115523

这篇关于PHP intl国家/地区代码2字符为国家名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆