Re: Regular expression help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



David Christensen wrote:
I just plain suck at regex, so I was hoping to get some hints from you
regex experts out there.  I'm sure it's been done a thousand times, but
I can't seem to find what I'm looking for with a simple google search:

$phone could be "1234567890" OR
$phone could be "123-456-7890" OR
$phone could be "(123) 456 7890 OR
$phone could have other unexpected characters in it, even control
characters.

So what I'm desiring to do is run some type of regex on $phone and only
return the integers and assign the cleaned string back to $phone.  I
thought I knew how to do this, but it's not working.

Thanks for your guidance.


If all you want is the digits....

$phone = preg_replace ( "/\D/", "", $phone );

Same as....

/[^0-9]/

--
John C. Nichel
ÜberGeek
KegWorks.com
716.856.9675
john@xxxxxxxxxxxx

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux