PHP code example of aklump / phone-number
1. Go to this page and download the library: Download aklump/phone-number 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/ */
aklump / phone-number example snippets
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter();
$number = $phone->format('3608881223');
// '(360) 888-1223' === $formatted
$default_area_code = 360;
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter($default_area_code);
$number = $phone->format('8881223');
// '(360) 888-1223' === $formatted
$number = $phone->format('888-1223', \AKlump\PhoneNumber\PhoneNumberFormats::SMS);
// '+13608881223' === $number
// Provide a custom default format.
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter(360, '+#CC#.#c#.###.####');
$number = $phone->format('888-1223');
// '+1.360.888.1223' === $number
// Convert to a JSON string.
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter(360, \AKlump\PhoneNumber\PhoneNumberFormats::JSON);
$number = $phone->format('888-1223');
// '{"country":"+1","areaCode":206,"localExchange":555,"subscriberNumber":1212}' === $number
$phone = (new \AKlump\PhoneNumber\USPhoneNumberFormatter();
$violations = $phone->validate('3608881223');
foreach($violations as $violation) {
echo $violation;
}
$is_valid = empty($violations);