preg_replace everything but 0-9

Associate
Joined
1 May 2006
Posts
810
Location
Bristol, UK
Hi All,

Totally stumped on this one.

I'm trying to remove everything except the numeric digits used in 3 URL variables that I'm using in my blog system. I can't seem to grasp the whole regex thing :confused: what do I need to put in there to exclude everything but 0-9?

Now that I think about it, these values will only be used in SELECT queries so I'm debating whether I need to secure them. Still, better safe than sorry. No?

As usual, all comments greatly appreciated.
Freakish_05
 
String functions are generally faster than regex functions:
Code:
<?php

$string = 'My name is Alan; some call m3 4L4N. H3YL0 LAWL!!';

$numbers = array();
for($i = 0; $i <= 9; $i++)
 $numbers[] = $i;

$string = str_replace($numbers, '', $string);
echo $string;

?>
:)
 
Last edited:
psyr33n said:
String functions are generally faster than regex functions:
Code:
<snip>
:)

isn't that going to replace the numbers with nothing and leave all other characters intact.... completely the opposite of the OP's requirement? :p
 
Back
Top Bottom