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

Recommended Answers

All 4 Replies

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

im getting � this symbol

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 for diafol

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.