Ok so i have a variable $phone which contains the string (407)888-9999 and I have this code
if($phone != ''){ $phone = "<span id='telephone'>{$phone}</span>";}
return $phone;
This works fine but now the client wants to have a some padding in between the area code and the next three numbers. So i need the code to be like this
<span id='telephone'><span class='spacer'>(407)</span>888-9999</span>";
Given no one else mentioned this, I would strip out all non-numeric characters from the number. Once done you can use a regex to easily get the numbers, this way any format is valid and pretty much no matter what the user enters you can format it how you want it:
Should do it not matter how the phone number is entered as long as there are 10 digits.
UPDATE
You could also use the
preg_replacetechnique withsubstrand forego the need forpreg_match. This would actually be my preferred solution.