确定有关电话号码的信息并在 PHP 中重新格式化
我正在寻找一种方法来确定电话号码是国际格式还是本地格式,以及如果是国际格式它属于哪个国家/地区。如果它是本地格式,它应该提示用户输入国家/地区代码,然后将其转换为国际格式。
示例:
00447749123123 = 英国国际号码 - 重新格式为 447749123123
+447749123123 = 英国国际号码 - 重新格式为 447749123123
447749123123 = 英国国际号码
07749123123 = 英国国内号码 - 提示输入国家/地区代码并重新格式化为 447749123123
18775784000 = 美国国际号码
8775784000 = 美国国内号码 - 提示输入国家/地区代码并重新格式化为 18775784000
有谁知道这样的脚本是否存在,或者如果不存在如何执行此操作? IT 应该适用于尽可能多的国家(而不仅仅是英国和美国)。
I'm looking for a way of determining whether a phone number is in the international format or a local format, and if it's in the international format what country it belongs to. If it's in the local format it should prompt the user for the country code and then convert it into the international format.
Examples:
00447749123123 = international UK number - reformat to 447749123123
+447749123123 = international UK number - reformat to 447749123123
447749123123 = international UK number
07749123123 = national UK number - prompt for country code and reformat to 447749123123
18775784000 = international american number
8775784000 = national american number - prompt for country code and reformat to 18775784000
Does anyone know if such a script exists, or if not how to go about doing this? IT should work for as many countries as possible (not just the UK and US).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这样的脚本或网络服务不存在,几周前我研究了类似的东西。
由于各个国家/地区的电话号码长度不同,我认为您将很难创建一个适用于所有具有不同电话号码编写方式的国家/地区的脚本。
您必须对作为输入给出的电话号码做出假设。
基本上你有两种不同的方法。
我会选择第二个选项。
在您的示例中,数字 1 和 2 很容易被识别为国际号码。
数字 3 很难识别,因为它可能是英国国际号码或具有 12 位国内电话号码的未知国家/地区。
因此,我首先接受选项一和选项二作为有效的国际号码,并跳过选项三。
在事先不知道哪个国家/地区的情况下识别国家电话号码是不可能的,因为许多国家/地区将共享相同的格式。因此,让用户在网络表单中选择他们的国家/地区需要将国际代码添加到号码中。
I don't think such a script or web service exists, I researched something similar a couple of weeks back.
As various countries have different length phone numbers I think you'll have a hard time creating a script that works for all countries with all different ways of writing a phone number.
You have to make assumptions about the phone number given as input.
Basically you have two different approaches.
I'd go for option number two.
In your examples number 1 and 2 are easily identifiable as international numbers.
Number 3 is hard to identify, because it could either be an international UK number or an unknown country with 12 digit domestic phone numbers.
So I'd start with accepting option one and two as valid international numbers and skip number three.
Identifying national phone numbers without knowing which country it is in advance is impossible since many countries will share the same formats. Having users choose their country in a webform is therefore neccessary to add the international code to the numbers.
没有什么是免费的,但 Neustar 将是您最好的付费服务。我认为他们也提供国际号码服务,但您可能必须编写自己的 API 接口。另一条付费路线可能是 Twilio,但我不确定他们的国际选择。我知道一些较大的 SMS 聚合器可能会为其产品提供此功能,但不会作为独立的 API/服务。如果您正在寻找付费选项,您可以尝试 OpenMarket(MxTelecom 国际版)。只是一个想法
There is nothing free but Neustar would be your best paid service. I think they offer international number services as well but you might have to code your own API interface. Another paid route might be Twilio, but I'm not sure of their international options. I know some of the larger SMS Aggregators might offer this for their products but not as a stand alone API/service. If you're looking for a paid option you might try OpenMarket (MxTelecom for international). Just a thought