Sorry, I put something in my first answer.
PHP does not know the g modifier. If you just want to match it, use preg_match_all instead of preg_match , but preg_replace is greedy by default.
I tried this code on writecodeonline.com
$data = "Nutritional counseling <br /><br />Online รรร Clinic Visits except as specifically covered in the Certificate or EOC. รร<br /><br />"; $pattern = '/[^a-z0-9_<>\\ s!@ #$%^&*()+={}\\[\\]|\\/:;"\\'?.,ยฎ-]/i'; $data = preg_replace($pattern, '', $data); echo ($data);
and his work.
For some reason, it needs double escaping, if you don't need to, just remove every second slash in the pattern.
I cleaned up the character class a bit. Most characters need not be avoided when they are inside a character class, only those that have special meaning even inside such a class, for example. / when used as a regex separator, ' when used as a line separator ...
But in the end, even your code works there when I just change the code to double escaping.
source share