UTF8 and Japanese characters
Problem: Foreign character are not displayed as they should be. This includes German, Japanese, Russian and all others excluding English (works perfectly). Ones PHP makes a call to MySQL via jQuery AJAX call it should return the information and display it on the page. The data is called and is displayed. However for non-English characters the results are displayed as a "?".
In phpMyAdmin the data displayed as it should have been be it in Japanese, German ect ect. But ones fetched from MySQL it is not returned as such.
The problem is not caused by the 开发者_JAVA技巧browser as my browser supports all Languages encodings.
MySQL encoding: UTF8_GENERAL_CI
Page encoding: UTF-8
<meta charset="utf-8" />
The problem may be in the fetching of the data by PHP from MySQL since it seems fine in MySQL ones viewed via phpMyAdmin. So here is the code used to fetch this data from MySQL. Unless encoding has to be included in this file.
view.php (fetches needed data from MySQL may be a cause of encoding problem returning ???)
$q = mysql_query("SELECT * FROM `notice` WHERE nid = '".$nid."'");
$a = mysql_fetch_array($q);
$nid = stripslashes($a['nid']);
$note = stripslashes($a['note']);
$type = stripslashes($a['type']);
$private = stripslashes($a['private']);
$date = stripslashes($a['date']);
$author = stripslashes($a['author'])
;
PS. Edited to be more clear.
You most likely need to set the character set of your database connection to UTF-8.
How to do that depends on the database library you are using.
In the old mySQL library, it would be
mysql_query("SET NAMES utf8");
(pre mySQL 5.0.7) and
mysql_set_charset("utf8");
for mySQL 5.0.7 and newer.
try calling
mysql_query("SET NAMES utf8");
somewhere before your query. of course if you're on PHP.
See: http://www.w3.org/TR/html4/charset.html#h-5.2.2
So you should use:
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
Ideally this info shall be supplied in headers of HTTP response.
mysql utf-8 is not the real utf-8. it uses 3 bytes instead of 4. For real utf-8, you have to use utf8mb4:
mysql_query("SET NAMES utf8mb4");
mysql_set_charset("utf8mb4");
精彩评论