Solved

Japanese characters problem

Posted on 2007-03-26
2
264 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
ID: 18797878
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
ID: 18797883
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

808 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