RE: [PHP] Formatting phone numbers?

From: Date: Fri, 16 Apr 2004 16:24:07 +0000
Subject: RE: [PHP] Formatting phone numbers?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-183640@lists.php.net to get a copy of this message
Thanks! -----Original Message----- From: Jay Blanchard [mailto:jay.blanchard@niicommunications.com] Sent: April 16, 2004 7:33 AM To: BOOT; php-general@lists.php.net Subject: RE: [PHP] Formatting phone numbers? [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

« previous php.general (#183640) next »