Re: formatting a numeric string
| From: | Edward van Bilderbeek - Bean IT | Date: | Wed, 10 Apr 2002 14:14:06 +0000 |
| Subject: | Re: formatting a numeric string | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-92391@lists.php.net to get a copy of this message | ||
try:
print ereg_replace("^([0-9]{3})([0-9]{3})([0-9]*)$", "(\\1) \\2 - \\3",
$phone_number);
Greets,
Edward
----- Original Message -----
From: "Erik Price" <pricee@hhbrown.com>
To: <php-general@lists.php.net>
Sent: Wednesday, April 10, 2002 4:13 PM
Subject: [PHP] formatting a numeric string
> I have the following code --
>
> $phone_number = "8005551212";
> $phone_array = explode("", $phone_number);
> $phone_number = sprintf("(%s%s%s) %s%s%s-%s%s%s%s", $phone_array[0],
> $phone_array[1], $phone_array[2], $phone_array[3], $phone_array[4],
> $phone_array[5], $phone_array[6], $phone_array[7], $phone_array[8]);
>
> Is this really the best way to achieve $phone_number = "(800)
> 555-1212" ? Or am I taking the long way around, and there's a function
> that can do this better?
>
> Thanks,
>
>
> Erik
>
>
>
>
>
> ----
>
> Erik Price
> Web Developer Temp
> Media Lab, H.H. Brown
> pricee@hhbrown.com
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>