MySQL UTF8 for Chrome, UTF8 for IE, but HEADER UTF

2019-07-20 04:59发布

问题:

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.