RE: [PHP] including parenthesis, space and dashes in a phone number
- From: daevid@xxxxxxxxxx ("Daevid Vincent")
- Date: Fri, 30 Nov 2007 12:19:50 -0800
The kind of opposite of this, is what I use, in that it ADDs the () and -
if ((strlen($phone)) <= 14) $phone =
preg_replace("/[^0-9]*([0-9]{3})[^0-9]*([0-9]{3})[^0-9]*([0-9]{4}).*/",
"(\\1) \\2-\\3", $phone);
-----Original Message-----.
From: afan pasalic [mailto:afan@xxxxxxxx]
Sent: Friday, November 30, 2007 5:45 AM
To: php-general
Subject: [PHP] excluding parenthesis, space and dashes from
phone number
hi,
I store phone number in mysql as integer, e.g. (123) 456-7890
is stored
as 1234567890.
though, in search form they usually type in a phone number with
parenthesis/space/dashes. I have to extract numbers before I search
through mysql.
currently, I use eregi_replace() function, several times, to
do the job:
eregi_replace(' ', '', $phone);
eregi_replace('(', '', $phone);
eregi_replace(')', '', $phone);
eregi_replace('-', '', $phone);
and it works fine.
but, is there any better way? more "fancy"? :)
thanks for any help.
-afan
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
- Follow-Ups:
- Re: [PHP] including parenthesis, space and dashes in a phone number
- From: afan pasalic
- Re: [PHP] including parenthesis, space and dashes in a phone number
- References:
- excluding parenthesis, space and dashes from phone number
- From: afan pasalic
- excluding parenthesis, space and dashes from phone number
- Prev by Date: Re: [PHP] Rewind foreach loop
- Next by Date: Re: [PHP] including parenthesis, space and dashes in a phone number
- Previous by thread: Re: [PHP] excluding parenthesis, space and dashes from phone number
- Next by thread: Re: [PHP] including parenthesis, space and dashes in a phone number
- Index(es):
Relevant Pages
|