RE: [PHP] including parenthesis, space and dashes in a phone number



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


.



Relevant Pages

  • Re: [PHP] including parenthesis, space and dashes in a phone number
    ... Daevid Vincent wrote: ... [PHP] excluding parenthesis, space and dashes from ...
    (php.general)
  • Re: [PHP] excluding parenthesis, space and dashes from phone number
    ... [PHP] excluding parenthesis, space and dashes from phone number ... I store phone number in mysql as integer, ... in search form they usually type in a phone number with ...
    (php.general)
  • HTTP Error 500 - IsapiModule
    ... Don't know if this is the right group but I am having real problems trying to connect to my MySQL db with php. ... I am trying to create a search form. ... I can connect and display in my browser a simple call to a db record but when I try to execute my search script I get a 500 Internal Server error: ...
    (php.general)
  • Dreamweaver recordset will not give me null
    ... coding php for about 6 months now and the one thing ive always wanted ... search form without typing in a query) it lists all of the entries ... all night last night running through these groups and running through ...
    (comp.lang.php)