Re: Formatting phone numbers?

From: Date: Thu, 15 Apr 2004 22:11:57 +0000
Subject: Re: Formatting phone numbers?
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-183573@lists.php.net to get a copy of this message
Rob Ellis wrote:
On Thu, Apr 15, 2004 at 04:31:09PM -0500, BOOT wrote:
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.
substr_replace($string, '-', 3, 0);
Won't that replace the number, though, not insert the dash? $formatted_number = preg_replace('/^([0-9]{3})/,'\1-',$number); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.general (#183573) next »