?
Solved

Japanese characters problem

Posted on 2007-03-26
2
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 375 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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

801 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