UTF8 mysql encoded database, but not showing special characters in PHP

我的未来我决定 提交于 2019-12-11 06:09:13

问题


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:

My database and collations:

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


回答1:


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



回答2:


Try:

$variable = utf8_encode($valueCommingFromDB);



回答3:


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



来源:https://stackoverflow.com/questions/19281747/utf8-mysql-encoded-database-but-not-showing-special-characters-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!