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

PHP — how to remove special character

A special string : " the famous �red door� ";
how can i remove the special character : � , that I can get: "the famous re door"

>Solution :

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

To remove all the characters that do not fall under the above criteria, you have to add ^ after the opening angle bracket so the regular expression to be [^a-zA-Z0-9\s!?.,’"].

Example

<?php
$str = "Hey @there#! How ( are) you *d_oing/?";
echo preg_replace("/[^a-zA-Z0-9\s!?.,\'\"]/", "", $str);
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