Reputation: 373
I use this code:
preg_replace('/[^A-ÿ\d _]+/', 'NO' , $mystring]
To find and replace everything that is not alphanumerical, or a space or an underscore, with ***
Only problem is that, if my input is:
tes<<t
it outputs:
tesNOt
and I would like:
tesNONOt
I would like it replacing EVERY occurrence of the 'wrong' character.
Thanks for your help!
Upvotes: 1
Views: 530
Reputation: 47864
Your pattern is matching "one or more".
You want to match each one.
$mystring='tes<<t';
echo preg_replace('/[^A-ÿ\d _]/', 'NO' , $mystring);
// output: tesNONOt
Upvotes: 1