views:

821

answers:

3

hi my friends , i just want to know about the language transation for the Japanese, 1) Which is the best encoding for the database mysql 2) Which/how can i print that in HTML page. ? thanks in advance.

+3  A: 

UTF-8 without a doubt. Make everything UTF-8. To put UTF-8 encoded text on your web page, use this within your HEAD tag:

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

As for MySQL, put the following into your my.cnf (config) file:

[mysqld]
collation_server=utf8_unicode_ci
character_set_server=utf8
default-character-set=utf8
default-collation=utf8_general_ci
collation-server=utf8_general_ci

If you're getting garbage characters from the database from queries executed by your application, you might need to execute these two queries before fetching your Japanese text:

SET NAMES utf8
SET CHARACTER SET utf8
karim79
It's easier to just set the default_charset in phpini_set( 'default_charset', 'UTF-8' );
Peter Bailey
Great but he hasn't mentioned PHP anywhere, and putting a meta tag into a document is much simpler than tweaking a setting. Plus, that could fail if he's on a shared host.
karim79
Wait, it's there now, either I didn't see it or it was just added.
karim79
+2  A: 

Make Sure

  1. Database is in UTF8
  2. Database Table is in UTF 8
  3. Output Headers are in UTF 8
  4. HTML Meta Tag is in UTF 8

When everything is talking the encoding you can live happily :)

For MySQL: utf8 charset, utf8_general_ci collation For PHP headers:

header('Content-type: text/html; charset=UTF-8') ;

For HTML

<meta http-equiv="Content-type" value="text/html; charset=UTF-8" />
Shadi Almosri
thank you very much mr Shadi Almosri...thank you very much....and could you please tell me..1. Japanese - 2. English3. French4. Italian5. Turkish6. German7. Spanishfor all these language into a single system which is more suitable encoding ???
coderex
UTF8 is made to handel them all very well, i recently released a website in 6 languages including polish, german, spanish, french, italian, greek. UTF 8 will cover the languages you've specified.
Shadi Almosri
is there any issue with any browser to display these many languages, i meant in some times i have problems...how you solve that kind of issu with unsupported font characters?
coderex
Just make sure you use a font that supports such charecters in your page. In this case using something like arial is a safe bet, you can see this by simply going to a web page such as: http://www.google.com/search?q=japanese+website you'll see you don't need anything to display them. Just ensure all your encoding in every part of your system uses UTF8 and then use a standard font such as arial for the web page display.
Shadi Almosri
Also the link provided by Peter Bailey is a very useful step by step guide to ensuring the setup i've outlined above is correct. http://developer.loftdigital.com/blog/php-utf-8-cheatsheet
Shadi Almosri
ok...thank you.. it will be very helpfull for me..and One more thing.. how can i set this in PGSQL ??collation_server=utf8_unicode_cicharacter_set_server=utf8default-character-set=utf8default-collation=utf8_general_cicollation-server=utf8_general_ci????
coderex
What do you use to create your postgres tables? do you have a control panel such as phppgadmin or are you using pure SQL statements?
Shadi Almosri
Here is a link that might help you for postgresql setup of a unicode db: http://www.olat.org/docu/install/Database_and_UTF-8_configuration.htmlThe line of interest is:CREATE DATABASE testdbWITH OWNER = replace_with_your_admin_user_eg_pgsqlENCODING = 'UNICODE'TABLESPACE = pg_default;
Shadi Almosri
am useing another pgsqladmin III application
coderex
Well there should be a function within it when creating the database to set the "Encoding" to "Unicode", that will have the same affect as when creating the MySQL tables.If all the information so far has been helpful to get you carrying out the requires features, then please tick the answer as "Answered"Shadi
Shadi Almosri
A: 

I'd definitely refer to the now-somewhat-canonical PHP UTF-8 Cheatsheet

Peter Bailey