1

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!

0

1 Answer 1

1

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

Demo Link

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! Nice and smooth!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.