Re: Formating a string to telephone format - (123) 456 - 7890
| From: | David Newcomb | Date: | Mon, 26 Jun 2000 14:17:50 +0000 |
| Subject: | Re: Formating a string to telephone format - (123) 456 - 7890 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-3117@lists.php.net to get a copy of this message | ||
Try:
<?php
function format_tel($number)
{
switch (strlen($number))
{
case 7:
return ereg_replace("(...)(....)",
"\\1 - \\2",
$number);
break;
case 10:
return ereg_replace("(...)(...)(....)",
"(\\1) \\2 - \\3",
$number);
break;
default:
return "len=$number";
break;
}
}
echo "1234567890 = " . format_tel("1234567890") . "<br>\n";
echo "1234567 = " . format_tel("1234567") . "<br>\n";
?>
----- Original Message -----
From: Sean Mathews <smathews@dceg.com>
To: <php-general@lists.php.net>
Sent: Monday, June 26, 2000 3:19 PM
Subject: [PHP-GENERAL] Formating a string to telephone format - (123) 456 -
7890
> Heya Guys
>
> This is surely very simple, but Im new. I need to create a function to
> format a variable length string to a telephone format. Thus 1234567890
> becomes (123) 456 - 7890, and 1234567 becomes 123 - 4567 etc etc. I
havent
> been able to find any procedures to copy portions of strings. Please drop
> me a hint.