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
this takes 7, 10 and 11 digit, removes additional characters and adds dashes by going right to left through the string. change the dash to a space or dot.
$raw_phone = preg_replace('/\D/', '', $raw_phone);
$temp = str_split($raw_phone);
$phone_number = "";
for ($x=count($temp)-1;$x>=0;$x--) {
if ($x === count($temp) - 5 || $x === count($temp) - 8 || $x === count($temp) - 11) {
$phone_number = "-" . $phone_number;
}
$phone_number = $temp[$x] . $phone_number;
}
echo $phone_number;