Re: [PHP] excluding parenthesis, space and dashes from phone number
- From: jochem@xxxxxxxxxxxxx (Jochem Maas)
- Date: Fri, 30 Nov 2007 16:16:52 +0100
afan pasalic wrote:
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);
side note: if you are doing simple string relacement (as in the code above)
don't use regular expression functionality to do it, it a waste.
the above code will work the same if you replace 'eregi_replace' with 'str_replace'
and it works fine.
but, is there any better way? more "fancy"? :)
see TGs example. I recommend doing some study on regexps - knowing abit about
them and how to write a basic regexp is an invaluable tool.
.
thanks for any help.
-afan
- Follow-Ups:
- Re: [PHP] excluding parenthesis, space and dashes from phone number
- From: afan pasalic
- Re: [PHP] excluding parenthesis, space and dashes from 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] excluding parenthesis, space and dashes from phone number
- Next by Date: Re: [PHP] excluding parenthesis, space and dashes from phone number
- Previous by thread: excluding parenthesis, space and dashes from phone number
- Next by thread: Re: [PHP] excluding parenthesis, space and dashes from phone number
- Index(es):
Relevant Pages
|