I am working on an SMS app and need to be able to convert the sender\'s phone number from +11234567890 to 123-456-7890 so it can be compared to re
Don't reinvent the wheel! Import this amazing library:
https://github.com/giggsey/libphonenumber-for-php
$defaultCountry = 'SE'; // Based on the country of the user
$phoneUtil = PhoneNumberUtil::getInstance();
$swissNumberProto = $phoneUtil->parse($phoneNumber, $defaultCountry);
return $phoneUtil->format($swissNumberProto, PhoneNumberFormat::INTERNATIONAL);
It is based on Google's library for parsing, formatting, and validating international phone numbers: https://github.com/google/libphonenumber