Jump to content

Japanese characters


Recommended Posts

Hi there,

 

I'm currently translating a Flash game into a number of different languages - highscores are saved to a db from Flash at the end of the game.

 

My current PHP code works fine with the German and Dutch translations (handles their foregin characters fine):

 

$firstname = htmlentities(strip_tags($_POST["firstname"]), ENT_QUOTES, "UTF-8");

 

My next translation is to Japanese!

 

Flash definitely encodes as UTF-8, but when used with Japanese characters things seem to fall over.

 

I enter: 美際投資基

 

Which should be encoded to this:

美際投資基

 

But actually appears as this:

美際投資基

 

I've tried changing the encoding in this string to "EUC-JP" and also "BIG5" in the PHP but it still returns the same.

 

Is there anything obvious I should be changing in the PHP or db itself?

 

I've never worked with Japanese before so any help is really appreciated!!!

 

Many thanks,

 

Matt

Link to comment
https://forums.phpfreaks.com/topic/110449-japanese-characters/
Share on other sites

This is taken from my personal code library that I compiled after having much frustration with the Japanese characters....I hope this helps.....

 

The database was and is set up like so:

 

Collation - utf8_unicode_ci OR sjis_japanese_ci

 

The tables were and are set up like so:

 

Collation - utf8_general_ci OR sjis_japanese_ci

 

 

The html page encoding was and is set up like so:

 

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

 

The hard coded Japanese characters would render correctly in the browser, but anything retrieved from the db came back as ??????. If I changed the encoding on the page to 'utf8' or 'default', the hard coded Japanese would become unreadable, but the db would return the correct Japanese record.

 

If, through my html page, I inserted data in the db, the inserted data was just a jumble of characters BUT a select query would return the correct Japanese record. So, the hard coded Japanese AND the data from the table rendered correctly, BUT the data was unreadable via PhpMyAdmin.....so that was not satisfactory.

 

 

However, by adding.....mysql_query("SET CHARACTER SET sjis"); immediatlely below my connection string, the problem went away and everything is just perfect.....yipee!!

 

 

So, if anyone is interested, if the tables and the db collation is set as I have described above, AND mysql_query("SET CHARACTER SET sjis"); is put right under your connection string, you should be fine. Of course if you want to add a different character set to the string you could replace sjis with utf8 or whatever.

 

 

 

Hope this helps somebody

 


<?php



// Make a MySQL Connection

mysql_pconnect("localhost", "username", "password") or die(mysql_error());

mysql_select_db("my_database") or die(mysql_error());



mysql_query("SET CHARACTER SET sjis");



?>

Link to comment
https://forums.phpfreaks.com/topic/110449-japanese-characters/#findComment-566812
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.