user2210405
user2210405

Reputation: 11

Japanese text outputs as question marks or goobledy gook

I have worked on this a while, and I tried many of the solutions proffered - to no avail.

In phpadmin the variables are utf8_unicode_ci.

A simple query with the following header:

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

Outputs question marks:

Gibberish text

If I add in the line mysql_query("SET NAMES utf8"); just before the query I get goobledy gook (mojibake):

enter image description here

Any help would be much appreciated.

Upvotes: 1

Views: 145

Answers (1)

Joni
Joni

Reputation: 111389

You should set the MySQL connection encoding to the same encoding you use on the page. The server converts the results it finds into this encoding, so that you don't have to care about how the data is actually stored.

Since setting the connection UTF-8 produces mojibake your page must have some different encoding. SJIS maybe? Here you'll find the CJK encodings that MySQL supports: http://dev.mysql.com/doc/refman/5.5/en/charset-asian-sets.html

The preferred way to set the ending is with mysql_set_charset. Executing SET NAMES works for encodings that are based on ASCII, like UTF-8, but will not work for others, like sjis. For example:

mysql_set_charset('cp932');

Also, don't use the mysql library in new programs. It has been deprecated and will be removed from PHP at some point.

Upvotes: 1

Related Questions