• Resolved lor_erik

    (@lor_erik)


    I have had difficulties with the displaying of Japanese characters in my Blog. Katakana characters and simple Kanji where fine but Hiragana and the more complex Kanji where impossible to display correctly. Actually most languages with complex (2 to 3 byte characters) had a problem.

    I’ve up and down about 25 different forums on WordPress and I must say I had a difficult time finding a solution to my problem. But since I found it, I tought that someone else might get in the same possition as me and need the same kind of help as I needed. It’s kind of frustrating to read a post to the end just to find out: “OH! I finnally found the solution… Thanks!” and then the solution is not displayed.

    Well here it is…

    I’m running an Apache Server 2.0.54
    PHP 5.0.4
    MySQL 4.1.12
    and WordPress 1.5.1.3

    The problem all originates from MySQL 4.1

    Starting from version 4.1, MySQL supports different language encodings for diffenrent applications and my prblem originated from the “Client” encoding language and the “Server” encoding language.

    The “Client” was set to Latin-1 encoding
    The “Server” was set to UTF-8

    MySQL tries to translate from one language to the other when it puts the information in its Database. The problem is, my WordPress encoding already was UTF-8. So MySQL basically took UTF-8 encoded text (from WordPress) and treated it as Latin-1 encoded text and tried to convert it to UTF-8. Doing that, some characters where fine but more complex ones where not…

    To solve this problem, you have to tell MySQL to treat all the stuff from WordPress as UTF-8 stuff. The way to do this is REAL simple.

    First open the file: wordpress\wp-includes\wp-db.php

    Find line 56, it should read as this:
    $this->select($dbname);

    Go to the beginning of the line and punch “enter” to make it move one line down and leave a blank line on line 56.

    Then place this line at line 56:
    $this->query(“SET NAMES a€?utf8a€2”);

    Then your lines should look like this:
    ?????– $this->query(“SET NAMES a€?utf8a€2”);
    ?????— $this->select($dbname);

    And Voil??!, you now have a wordpress that can display and retain text in any language your computer can write in ??

    One final note, your Database must be a UTF-8 Database and your WordPress encoding must be UTF-8 also. For wordpress, you can find this in Options/Reading.

    Hope this helps someone else and save him or her a lot of problems!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thank you so much for posting this. I was banging my head against the wall assuming that I had done something wrong. I must have installed WordPress 50 times before I chanced upon this message.

    lelion

    (@lelion)

    Hi! ??

    I was searching for help and I stumbled upon this message by Lor_Erik…

    I am trying to set up a bi-lingual blog (with the help of the GENGO plugin?? and all was OK, until the moment I opened phpMyAdmin and found that cyrillic characters, encoded as UTF-8, DO NOT display correctly in the DATABASE.

    The strange thing for me was that in the blog all was OK! All characters displayed correctly, encodings (both in the MySQL database and in the blog) were set to Unicode (UTF-8) and collation in the MySQL set to utf8_unicode_ci.

    So I searched around and finally have found the following code, which helped me resolve this bug:

    First, open wp-includes/wp-db.php

    Then find line 43 (WordPress 2.05), press ENTER after the end of the line, and add the following:


    mysql_query("SET NAMES 'utf8'");

    So the code becomes:

    function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
    $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
    mysql_query("SET NAMES 'utf8'");

    …instead of:

    function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
    $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);

    This (mysql_query(“SET NAMES ‘utf8′”);) tells WordPress to interact (send data and receive data) with the database, using UTF-8 encoding (that’s my guess). This is a great tip for new WordPress installs; for older ones, though, this might not work, because after you change this encoding setting in wp-db.php, older items no longer will be displayed correctly, only newly posted ones. But if you install WP for the first time, or do a new fresh install, it’s a great fix, because it’ll make EVERYTHING displayed as UTF-8, both in the website with the blog and in the MySQL database – this will help avoid future problems, when backup/restore MySQL database, etc.!

    //

    One thought, though – is there a difference between using:

    1) the method, described by Lor_Erik
    (find:
    $this->select($dbname);
    and then add before that:
    $this->query("SET NAMES 'utf8'");
    )

    and

    2) the method which I found
    (add code after line 43, so it becomes:

    function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
    $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
    mysql_query("SET NAMES 'utf8'");

    )
    …?

    Someone more experienced than me can maybe tell us the difference (or there’s no diference?)? ??

    Thank you!

    Happy blogging to everyone! :)))

    You rawk dude! I had problems showing my French characters(even if they are Latin!) and I was wondering what the hell was I doing wrong; I added that simple line and boom, everything is back to normal. Thanks for avoiding me a headache.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Japanese Characters not displaying right!’ is closed to new replies.