Page 1 of 1

help on preg_replace() please

Posted: Wed Mar 30, 2011 3:05 am
by helloise
i have:

Code: Select all

$msg = ereg_replace("[^A-z0-9]"," ",$msg);
$msg = ereg_replace("  "," ",$msg);
$msg = ereg_replace("    "," ",$msg);
how will i apply preg_replace please???
thank you

Re: help on preg_replace() please

Posted: Wed Mar 30, 2011 3:44 pm
by tr0gd0rr
The first one translates pretty well, but I do think you may want `a-zA-Z` instead of `A-z`. So for the first one, keep in mind that preg_* patterns must begin and end with a special character (traditionally a forward slash). The second two statements could be done with str_replace() since no patterns are being used.