RE: [PHP-GENERAL] Formating a string to telephone format - (123) 456 - 7890

From: Date: Tue, 27 Jun 2000 00:01:16 +0000
Subject: RE: [PHP-GENERAL] Formating a string to telephone format - (123) 456 - 7890
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-3247@lists.php.net to get a copy of this message
I use these two functions for American phone numbers which you can easily modify: <?php function phone_format ($phone) { $len = strlen($phone); if ($len>=10){ $str = sprintf("%s-%s-%s", substr($phone,0,3), substr($phone,3,3), substr($phone,6,4)); if (strlen($phone)>10){ $str .= sprintf(" x%s", substr($phone,10,99)); } }elseif ($len>=0){ $str = $phone; } return $str; } function phone_unformat ($phone) { return (ereg_replace("[^0-9]", "", $phone)); } ?> > -----Original Message----- > From: Sean Mathews [mailto:smathews@dceg.com] > Sent: Monday, June 26, 2000 7:19 AM > To: php-general@lists.php.net > 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. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.general (#3247) next »