PHP code example of erichowey / nanp-number-formatter

1. Go to this page and download the library: Download erichowey/nanp-number-formatter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

erichowey / nanp-number-formatter example snippets


use Erichowey\NanpNumberFormatter\NanpNumberFormatter;
...
$number = NanpNumberFormatter::format("(212) 555-0123");

echo $number->e164; // +12125550123
echo $number->nationalFormat; // (212) 555-0123
echo $number->nationalFormatPlusOne; // 1 (212) 555-0123
echo $number->internationalFormat; // +1 212 555 0123
echo $number->dotFormat; // 212.555.0123
echo $number->hyphenFormat; // 212-555-0123
echo $number->tendigit; // 2125550123
echo $number->elevendigit; // 12125550123
echo $number->uri; // tel:+12125550123
echo $number->npa; // 212
echo $number->nxx; // 555
echo $number->line; // 0123
...

$number = NanpNumberFormatter::format("(212) 555-****", true);

try {
    $number = NanpNumberFormatter::format("1234");
} catch (NanpNumberFormatterException $e) {
    echo $e->getMessage(); // 1234 is less than 10 characters
}