libphonenumber for php

橙三吉。 提交于 2019-12-11 23:19:38

问题


I am using https://github.com/davideme/libphonenumber-for-PHP for formatting phonenumbers

I am having issue with 1800 numbers

$formatnumber = "1800123456"
$country = "AU";    

$phoneUtil = PhoneNumberUtil::getInstance();

try {
    $NumberProto = $phoneUtil->parse( $formatnumber , $country );
} catch ( NumberParseException $e ) {
    echo $e;
}

$formattedNumber =  $phoneUtil->format( $NumberProto, PhoneNumberFormat::NATIONAL );

What I am expecting to get back from $formattedNumber is "1800 123456"

What I get back is an unformatted number "1800123456"

If there something I need to do doing to get it to format correctly?


回答1:


It works for me with pretty much your code:

<?php
require __DIR__ . '/vendor/autoload.php';


$formatnumber = "1800123456";
$country = "AU";

$phoneUtil = \libphonenumber\PhoneNumberUtil::getInstance();

try {
    $NumberProto = $phoneUtil->parse($formatnumber, $country);
} catch (NumberParseException $e) {
    echo $e;
}

$formattedNumber = $phoneUtil->format($NumberProto, \libphonenumber\PhoneNumberFormat::NATIONAL);

echo $formattedNumber;

Response:

1800 123 456

I am using my version of libphonenumber-for-php though: https://github.com/giggsey/libphonenumber-for-php



来源:https://stackoverflow.com/questions/15125433/libphonenumber-for-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!