Home > Back-end >  PHP -- how to remove special character
PHP -- how to remove special character

Time:08-04

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

CodePudding user response:

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);
  • Related