Solved

Japanese characters problem

Posted on 2007-03-26
2
268 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 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

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…
This article discusses how to implement server side field validation and display customized error messages to the client.
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…
The viewer will learn how to dynamically set the form action using jQuery.

728 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