获取国家代码

发布于 2024-09-13 16:41:21 字数 216 浏览 2 评论 0原文

我可以使用 TelephonyManager::getNetworkCountryIso() 获取 ISO 形式的国家/地区代码,因为它返回 US 表示美国等,但如何获取数字国家/地区拨号代码?

我似乎找不到任何函数为我提供所需的数据,因为我需要一个函数(例如)为美国/加拿大返回 0192 巴基斯坦等。

I can get the country code in ISO-form using TelephonyManager::getNetworkCountryIso(), as it returns US for USA and such, but how can I get the numeric country dialing code?

I can't seem to find any functions provides me with the data I'm looking for, as I need a function that (for example) returns 01 for USA/Canada, 92 for Pakistan and so on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

揽清风入怀 2024-09-20 16:41:21

由于它们是一个简短的列表,具有到字母代码的清晰映射,您是否可以只存储一个映射?

我不确定这是否是您想要的,因为巴基斯坦的 ISO 数字国家代码是 586,而您的问题引用了“92”,这是巴基斯坦的国际拨号代码。但同样的原理也可以发挥作用。

Since they're a short list, with a clear mapping to the alpha codes, could you perhaps just store a mapping?

I'm not sure this is what you want though, since the ISO numeric country code for Pakistan is 586 and your question quotes "92", which is the international dialing code for Pakistan. The same principle would work though.

婴鹅 2024-09-20 16:41:21

您可以在 http://country.io/phone.json< 获取 ISO2 国家/地区代码到国际拨号代码的 JSON 映射/a>.下面是一个使用它的简单 PHP 示例:

$codes = json_decode(file_get_contents("http://country.io/phone.json"), true);
echo $codes['US'];
// => 1
echo $codes['PK'];
// => 92

请参阅 http://country.io/data/ 了解更多信息相关数据。

You can get a JSON mapping of ISO2 country code to international dialing code at http://country.io/phone.json. Here's a simple PHP example that makes use of it:

$codes = json_decode(file_get_contents("http://country.io/phone.json"), true);
echo $codes['US'];
// => 1
echo $codes['PK'];
// => 92

See http://country.io/data/ for more related data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文