preg_replace in PHP - regular expression for NOT condition
You can use a negated character class (using ^
at the beginning of the class):
/[^\da-z]+/i
Update: I mean, you have to use a negated character class and you can use the one I provided but there are others as well ;)
Try
preg_replace("/([^a-zA-Z0-9]+)/","*",$mystring);
You want to use a negated "character class". The syntax for them is [^...]
. In your case just [^\w]
I think.