Forum Moderators: coopster

Message Too Old, No Replies

Strip All Except Numbers

Strip All Except Numbers

         

BlackRaven

3:45 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



is there a function in PHP that will strip all character except numbers?

leatherback

4:13 pm on Aug 29, 2005 (gmt 0)

10+ Year Member



$new_string = ereg_replace("[^0-9]", "", $string);
, I think

coopster

4:59 pm on Aug 29, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think so too ;)

I often use the perl compatible expressions [php.net] though as they are a faster alternative:

$number = preg_replace("/[[:^digit:]]/", '', $number);

Either solution should work.