Solved

mb_convert_encoding and UTF-8 to GB2312 conversion

Posted on 2004-08-19
4
809 Views
Last Modified: 2012-06-21
I am currently developing a web application that displays all HTML pages in UTF-8 encoding. The application also contains an online form where users can enter the a message and send it out as an email in GB2312 format. However, if I change the online form's encoding to GB2312 so that the text input by the user is encoded with GB2312, the UTF-8 encoded text in the HTML form gets garbled.

Therefore, I decided to keep the online form encoded in UTF-8, and use iconv or mb_convert_encoding to convert UTF-8 encoded text into GB2312 (Simplified Chinese). It seems, however, neither iconv nor mb_convert do a 100% thorough job of converting the UTF-8 text. With iconv, certain special characters such as - or , do not get converted properly. And when iconv encounters a character it doesn't recognise, it tends to stop the conversion right there and then, so I only receive half of the converted text up to the point where the unrecognised character was found.

mb_convert_encoding also has problems recognising certain chinese characters and these characters get garbled during the conversion.

I'm new to all this utf-8 encoding stuff, so I was wondering if there is a way to provide mb_convert or iconv with the most up-to-date charsets in order to ensure all characters are translated correctly without being garbled. Actually, I'm not even sure if obtaining the latest charsets is the correct solution. Has anybody ever experienced this kind of problem with iconv or mb_convert_encoding? And if so, did you find a solution?

Many thanks for your help.
0
Comment
Question by:philippo123
[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
4 Comments
 
LVL 29

Expert Comment

by:fibo
ID: 11925900
Hi,
These charsets things can be awful at times!
You'll probably need to check first WHICH problem you are experiencing...
1 - A simple test would be, when getting a web page with "wrong" characters displayed, to identify what is exactly happening. First, change the character code used by your web browser (easy with netscape and IE, mode difficult with opera) for the page (OR the frame if your page has frames). Experience several codes to see which character display fine and which display wrong: this will allow you to see what is happening. A stupid example I experienced was that the char code for my web page was UTF-8, that the chars coming from MySQL were displayed in UTF8, but that some chars I had entered in the php codes were NOT utf8. Of course this leads to several crazzy variations!
2 - You might also to be 100% sure ask for some chars strings to be displayed not only in char form but also in hex, so that you can manually check what is appening.
3 - If you use phpmyadmin to check values in MySQL, be aware that you have 2 frames and that iin some occasions you canNOT get the right code in the data (rightmost) frame.
4 - Maybe you have a live link at which we can brows and experiment?
0
 

Author Comment

by:philippo123
ID: 11970658
Thanks, but I've decided not to use the PHP converters to solve this problem anymore.  What I've been doing to work-around this conversion problem is to use a pop-up window which is encoded in GB2312 to allow the user to input data. This way, the text is entered directly into the system as GB2312, eliminating the need to convert it from UTF-8. Not a perfect solution, but it will have to do for now.

Thanks for your offer though
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12516642
PAQed, with points refunded (125)

modulo
Community Support Moderator
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
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 …

623 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