MySQL UTF8 for Chrome, UTF8 for IE, but HEADER UTF8 for Chrome and UTF-8 for IE?

戏子无情 提交于 2019-12-24 01:44:39

问题


With this:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

IE displays properly Chrome displays properly

With this:

<meta http-equiv="Content-Type" content="text/html; charset=utf8"> 

(without the - between f and 8)

IE displays èéàä etc. with è$ etc. Chrome displays properly

Then I have a SQL Connection (database setted with utf8_unicode_ci or ascii_general_ci)

mysqli_set_charset('utf8')

IE and Chrome display èéàäö properly when posting the results

mysqli_set_charset('utf-8')

IE and Chrome display è$ etc. or ????? when posting the results

How about the other browsers? Why?


回答1:


In the Content-Type meta tag, the valid way is:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

The reason Chrome displays properly is because it is more accepting of errors in this case whereas IE requires it to be written properly.

However it's different with MySQL. They decided to go with the short names. Here is a list of supported character sets. This is something done server-side, so it won't matter what browser you are using.

You can also execute the following query:

SHOW CHARACTER SET LIKE 'utf%'

Edit:

Make sure that you are using the same character set to INSERT into your database or this could cause undesired effects when you go to view it again.



来源:https://stackoverflow.com/questions/14742000/mysql-utf8-for-chrome-utf8-for-ie-but-header-utf8-for-chrome-and-utf-8-for-ie

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