I am looking at using libphonenumber to convert numbers into friendly local phone numbers
eg. if 19311234567 is entered it returns (931) 123 4567
I found a php version of libphonenumber here: https://github.com/davideme/libphonenumber-for-PHP but I cannot figure out how to use it to get what I am after.
So I am wondering if anyone knows what calls I need to make to it in order to get the phone number converted
With the actual implementation you can format with the following code.
$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));
Output:
string(15) "+1 931 123 4567"
string(12) "931 123 4567"
string(15) "+1-931-123-4567"
The rawInput and free format is not yet implemented in PHP version, but the API will be similar to the JAVA one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With