简体   繁体   中英

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"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM