How to remove special characters but still allow HTML tags.Im getting data from Mysql Database

I guess there is no such inbuilt function in PHP, so you have to do it manually by creating a custom function of your choice. something like below -

$arr_find = array('!', '?');
$arr_replace = arrray('', '');
$processed_str = str_replace($arr_find, $arr_replace, $target_str);

you need to use correct encoding type to display such characters.Please read about UTF-8 encoding type.Make sure you are trying to retrieve them in the correct encoding type as saved with some encoding type in the database

Member Avatar


Most modern examples of DBs I've seen are using charset utf8mb4 and collation utf8mb4_unicode_ci

If you have php output or processing before or without a html <meta charset="utf-8"> then before all that code, close to the top of the page, place this:

header('Content-Type: text/html; charset=utf-8');

Combining the db and php encoding should prevent most of the dreaded "black ? diamonds" from showing

So do you still need to remove special chars?