Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Preg Replace a curly apostrophe?

I’m trying to use preg replace to replace a single curly postrophe (amongst other characters but I have excluded them from my example).

preg_replace('/[‘]/', 'x', '‘');

Unfortunately the above outputs xxx, I would expect to only see a single x. Where am I going wrong?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Make it unicode capable by adding the u flag.

echo preg_replace("/[‘]/u", 'x', '‘');

prints

x
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading