<?php
function formatPhoneNumber($phoneNumber) {
// Remove all non-digit characters
$phoneNumber = preg_replace('/\D/', '', $phoneNumber);
// Add formatting based on your desired format
return str_replace(['000', '111', '222', '333', '444', '555', '666', '777', '888', '999'], ['(', ') ', '-'], $phoneNumber);
}
// Test the function
$phoneNumber = "123-456-7890";
$formattedNumber = formatPhoneNumber($phoneNumber);
echo "Formatted Phone Number: " . $formattedNumber;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter