�(问号)从mysql数据库获取文本时显示替换逗号[重复]

�(问号)从mysql数据库获取文本时显示替换逗号[重复]

问题描述:

This question already has an answer here:

Everytime i get some text to display on a page using php echo, all the inverted comma's are replaced by some stupid question mark signs like this: �

Anyone have any idea why this happens?

Encoding: Page- charset=utf-8 Database- MySQL charset: UTF-8 Unicode (utf8)

</div>

此问题已经存在 这里有一个答案: p>

  • UTF-8一直到 14 answers span> li> ul> div>

    每当我使用php echo在页面上显示一些文本时,所有反转的逗号都被替换为 一些愚蠢的问号这样的标志:� p>

    任何人都知道为什么会发生这种情况? p>

    编码: -charset = utf-8 \ nDatabase- MySQL charset:UTF-8 Unicode(utf8) p> div>

Just matched both the encoding of my page and database. They were different. Made them the same and that worked fine

Authough the collation of the database is "utf8-unicode-ci", the connection built by PHP side might use latin1 charset. So you would better check that by

echo $mysqli->character_set_name();

or

echo mysqli_character_set_name ($conn);

To set the charset to utf8, do

mysql_query("SET NAMES 'utf8′", $conn);

or

$mysqli->set_charset("utf8");

Hope it helps.