Forum Moderators: coopster

Message Too Old, No Replies

RegEX - Get all Numbers

         

almo136

5:22 pm on Jun 14, 2010 (gmt 0)

10+ Year Member



I have this code:

$string = "123456ABcd9999";
$answer = ereg("([0-9]*)", $string, $digits);
echo $digits[0];

This outputs '123456'. I'd like it to output '1234569999' ie. all the digits. How can I achieve this. I've been trying lots of different regex things but can't figure it out.

Readie

6:10 pm on Jun 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Don't use ereg - it's deprecated.

The following should work:

preg_match_all('/[\d]+/', $input, $out);
$output = implode('', $out[0]);
echo $output;