Re: formatting a string
| From: | Tom Rogers | Date: | Sun, 25 Apr 2004 01:53:32 +0000 |
| Subject: | Re: formatting a string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-184543@lists.php.net to get a copy of this message | ||
Hi,
Sunday, April 25, 2004, 11:17:16 AM, you wrote:
AB> hi...
AB> i have a string i want to pull out of a database (mysql). the column name is
AB> Phone1 and it is a 10 digit phone number. the raw string coming out of the
AB> table column would look like this: 1234567890
AB> what i want to do is format the string on display like this: (123)456-7890
AB> but dont quite know how to start with that. what function(s) would i use for
AB> that?
Try this:
$phone = '1234567890';
$newphone = preg_replace('/(\d{3})(\d{3})(\d)/','(\1)\2-\3',$phone);
echo $newphone.'<br>';
--
regards,
Tom