[snip]
Thanks for any help, even if you just suggest built in functions to look
at.

I'm looking for a way to take a 7 digit number and put it into xxx-xxxx
format.

So basically the logic is to count 3 characters into $number and insert
a
"-" there.
[/snip]

As a telecom we use several methods, but here is a small function which
allows us to keep both formats where needed

function addTNDashes ($oldNumber){
   $newNumber = substr($oldNumber, 0, 3) . "-" . substr($oldNumber, 3,
4);
   
   return $newNumber;
}

$telephone = "8654321";
$newTele = addTNDashes($telephone);
echo $newTele;

output is 865-4321 and we can still use $telephone if we need to. 
[stuff you may not need]
This is a boiled down version of a longer function that counts string
lengths to determine how many dashes might need to be added. Let's say
you have the area code in the number, like 2108765432. Being a ten digit
number with a recognizable area code we can then add a portion to the
function to add the two needed dashes, making the number more readable.
[/stuff]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to