Re: phone number formatting

From: Date: Thu, 02 Nov 2000 08:23:25 +0000
Subject: Re: phone number formatting
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-23344@lists.php.net to get a copy of this message
Jerry Lake wrote:
If I have phone numbers stored in my database as "1234567890" when I call them out to a page how can I display them as "(123) 456-7890" some sort of ereg_replace(); I'm guessing, but not sure how to structure. any help is appreciated Regards,
Not sure if you've had this one answered yet, but here's one way to do it. <?php $phonenum = '1234567890'; $area = substr($phonenum, 0, 3); $prefix = substr($phonenum, 3, 3); $four = substr($phonenum, 6, 4); print "(${area}) ${prefix}-${four}"; /* probably don't even need the curly braces */ ?> -Brian

« previous php.general (#23344) next »