首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >libphonenumber php用法

libphonenumber php用法
EN

Stack Overflow用户
提问于 2012-02-29 07:58:09
回答 2查看 4.3K关注 0票数 3

我正在考虑使用libphonenumber将数字转换为友好的本地电话号码

例如:如果输入19311234567,则返回(931) 1234567

我在这里找到了libphonenumber的一个php版本:https://github.com/davideme/libphonenumber-for-PHP,但我不知道如何使用它来获得我想要的东西。

所以我想知道有没有人知道我需要给它打什么电话才能转换成电话号码

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-04 20:18:44

对于实际的实现,您可以使用以下代码进行格式化。

代码语言:javascript
复制
$phoneNumberUtil = PhoneNumberUtil::getInstance(); 
$exampleNumber = new PhoneNumber();
$exampleNumber->setCountryCode(1)->setNationalNumber(9311234567);
var_dump($phoneNumberUtil->format($exampleNumber, PhoneNumberFormat::INTERNATIONAL));
var_dump($phoneNumberUtil->format($exampleNumber, PhoneNumberFormat::NATIONAL));
var_dump($phoneNumberUtil->format($exampleNumber, PhoneNumberFormat::RFC3966));

输出:

代码语言:javascript
复制
string(15) "+1 931 123 4567"
string(12) "931 123 4567"
string(15) "+1-931-123-4567"

rawInput和free格式在PHP版本中还没有实现,但API将类似于JAVA格式。

票数 2
EN

Stack Overflow用户

发布于 2016-02-03 20:45:39

我已经开发了API服务,它实际上是libphonenumber的包装器。

您可以获取电话号码的National格式:

代码语言:javascript
复制
curl http://phonenumber.ones-app.com/national-format?number=19311234567

(931) 123-4567

有关完整帮助,请访问:http://blog.ones-app.com/ones-phone-number-api/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9491701

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档