giggsey/libphonenumber-for-php-lite
Lite PHP port of Google’s libphonenumber for parsing, formatting, storing, and validating international phone numbers. Includes core PhoneNumberUtils only (no geolocation/carrier/short numbers). Requires PHP 8.1+ and mbstring; install via Composer.
A class that finds and extracts telephone numbers from text.
A search instance can be created by using PhoneNumberUtil::findNumbers()
Returns an instance of PhoneNumberMatcher, which can be iterated over (returning PhoneNumberMatch objects).
It searches the input $text for phone numbers, using the $defaultRegion. There are also optional parameters to set the phone number $leniency (look in Leniency for possible values), and the $maxTries to search for the phone number.
$phoneNumberUtil = \libphonenumber\PhoneNumberUtil::getInstance();
$text = "Hi, can you ring me at 1430 on 0117 496 0123. Thanks!";
$phoneNumberMatcher = $phoneNumberUtil->findNumbers($text, 'GB');
foreach ($phoneNumberMatcher as $phoneNumberMatch) {
var_dump($phoneNumberMatch->number());
}
// (PhoneNumber) Country Code: 44 National Number: 1174960123
How can I help you explore Laravel packages today?