Currently in my php application I have the following code that formats the unformatted 10 digit australian phone number to XX XXXX XXXX. What I would like to do is if the phone number in the database starts with 04 then it will format it as 4,3,3 like XXXX XXX XXX otherwise will maintain the 2,4,4 formatting. All phone numbers are stored in the database as XXXXXXXXXX.
Here is my code so hopefully someone can shed some light. I know there needs to be an if statement, but unsure how to check the first 2 digits of the number for the 04.
<?php
$num = $record['busphone'];
$phoneformated = substr($num,0,2)." ".substr($num,4,4)." ".substr($num,6);
echo "Ph: " . $phoneformated; ?>
Aucun commentaire:
Enregistrer un commentaire