Solved

Japanese characters problem

Posted on 2007-03-26
2
257 Views
Last Modified: 2011-09-20
I am about to develope a website in Japanese using PHP and mySQL but I have problem displaying Japanese character correctly. The data is retrieved from the database. My site is encoded in JIS-Shift

The question is: which character set should I use to store my data?

Thank you
0
Comment
Question by:khoama
  • 2
2 Comments
 

Expert Comment

by:ajd777
Comment Utility
Your best bet would be UTF-8. for both the site and the database, but no matter what you choose they should be the same. Otherwise it is like trying to translate a German book with a French dictionary.
0
 

Accepted Solution

by:
ajd777 earned 125 total points
Comment Utility
Actually your "real" best bet would to just encode everything as HTML entities when you store it in the database. This will ensure it displays properly no matter what encoding the page uses.

To convert characters to entities you cold use a Javascript like:

function convertfromchars(someelementid){
      var content = document.getElementById(someelementid).value;
      var result = '';
      for (i=0; i<content.length; i++)
    {
        charCode = content.charCodeAt(i);
        if (charCode <= 127)
            result += content.charAt(i);
        else
            result += '&#' + charCode + ';';
    }
      document.getElementById(someelementid).value = result;
}

or you could do it in PHP by using a function like:

function fix_chars($content,$encoding=''){
 if(!$encoding){$encoding = "AUTO";}
             $content=mb_convert_encoding($content,"HTML-ENTITIES",$encoding);
       return $content;
 }
0

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now