Re: [PHP] excluding parenthesis, space and dashes from phone number
I suck at regex.. but found this a while ago. Supposedly it'll strip all
non-numeric characters, so I've used it for phone #'s and SSNs:
preg_replace ('/[^\d]+/s', '', $var)
-TG
----- Original Message -----
From: afan pasalic <afan@xxxxxxxx>
To: php-general <php-general@xxxxxxxxxxxxx>
Date: Fri, 30 Nov 2007 08:44:38 -0500
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
- 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) - Re: I am totally stumped..with this on..LOAD_FILE Mysql+PHP= FSCK!!
... What I am trying to do is to upload files and stuff them in a mysql database. ... I copied the temporary file to somewhere else, and then handed it to MySQL..THAT WORKED.. ... Is there a way to force a close on the file..maybe that's the problem Mysql is opening a file that is not flushed to disk maybe? ... I gew the feeling its maintaining its own picture of file objects, and doesn't actually flush to the disk unless you do a copy or close php.. ... (comp.lang.php) - Re: I am totally stumped..with this on..LOAD_FILE Mysql+PHP= FSCK!!
... What I am trying to do is to upload files and stuff them in a mysql database. ... I copied the temporary file to somewhere else, and then handed it to MySQL..THAT WORKED.. ... Is there a way to force a close on the file..maybe that's the problem Mysql is opening a file that is not flushed to disk maybe? ... I gew the feeling its maintaining its own picture of file objects, and doesn't actually flush to the disk unless you do a copy or close php.. ... (comp.lang.php) - Re: com_dotnet
... And if MySQL isn't installed, the DLL won't load and phpinfowill show MySQL support isn't enabled. ... The MySQL interface is NOT compiled into PHP on the distributed Windows binaries - or you'd never be able to run PHP unless you had MySQL installed. ... *SOME* extensions are protocols, some are functional resources, and some are just type libraries. ... If you're going to compile the extension into PHP itself, the libraries must be available at compile time, and when you run PHP, or PHP won't load. ... (comp.lang.php) - Re Re: PHP 5.2.4 <= various mysql functions safemode & open_basedir bypass
... > various mysql functions safemode & open_basedir bypass ... PHP is currently very used because it's easy to use. ... Apache has directory restrictions. ... # if the mysql user has perms, ... (Bugtraq) |
|