Forum Moderators: coopster

Message Too Old, No Replies

preg match acting strange

returns 1 always

         

phazei

6:06 am on Apr 16, 2009 (gmt 0)

10+ Year Member



I'm guessing I'm doing something wrong, but:

echo preg_match("/[0-9]*/","aaaa", $matches)."\r\n";
print_r($matches);

outputs:
1
Array ( [0] => )

The array is empty, so what is wrong?

phazei

6:09 am on Apr 16, 2009 (gmt 0)

10+ Year Member



err, my goal is
if (preg_match("/[^0-9a-z \-]*/i", $string)) { ... }

I want it to return 1 if it matches anything that is not 0-9, a-z, A-Z, space, hyphen. Otherwise 0.

phazei

6:12 am on Apr 16, 2009 (gmt 0)

10+ Year Member



Oh damn!
The * should be a + for one or more, not 0 or more.
Duh