Question

I have a database with utf_general_ci encoding in MySQL, when I insert data in Navicat or PhpMyAdmin and do queries there, the special characters are returned fine.

But in a php variable they are showing like this:

how they show

My database and collations:

database

and in my html doc if it is a normal

it shows the characters OK, it only not work when is a php variable

please help me

Was it helpful?

Solution 3

Hei,

Firstly be sure you have this meta in html tag

<meta charset="UTF-8">

You can check also with this line in php, above you mysql extraction

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

If you store your special character in database as html code like this &#39; which is ' when you extract try to use this php function

htmlspecialchars_decode($your_text_from_db);

OTHER TIPS

Try:

$variable = utf8_encode($valueCommingFromDB);

It's important to note that utf8 in mysql is fairly limited, especially utf8_general_ci. You might want to switch to utf8_unicode_ci or utf8mb4

What's the difference between utf8_general_ci and utf8_unicode_ci

http://mathiasbynens.be/notes/mysql-utf8mb4

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top