Page 1 of 1

UTF-8 Encoding and Decoding

Posted: Fri Jul 28, 2006 10:18 pm
by joesmithf1
Hi,

I have a website where I am selling to customers in China. I have an online form where they can enter their information in chinese characters. Now the form works fine; data got submitted and stored in the mySQL database.

The problem is, when i go into mySQL database to view the records, the chinese characters that were entered by my customers are some were number coding system. My hosting provider told me i need some kind of special php functions to 'encode' and 'decode?' If I know what the heck they are or even know how to do it, that would help. Please help.....

All I need are three things
1. a code that shows how to ENCODE an input
2. a code that shows how to DECODE an input
3. where do i apply this encode and/or decode; do i have to set anything in my mySQL database?

Thank you.

Leon

Posted: Sat Jul 29, 2006 3:11 am
by onion2k

Code: Select all

mysql_query("SET NAMES = UTF8;");
Do that prior to your select query and MySQL should return the data as UTF8 rather than encoded. Alternatively use MySQL's CONVERT() function.

Note: Most people in China use either Big5 or GB2312 .. If their browser is obeying your HTML language declaration then the form data should be UTF8 .. but I've found a lot of the time that isn't the case. Data frequently gets messed up. If you find that happens, could you let me know the solution. :)

Posted: Sun Jul 30, 2006 11:10 am
by joesmithf1
Hi,

Thank you! Your suggestion brings up another question. Does this means I will NOT be able to view the chinese characters in the mySQL database? I'll have to 'query' it from the database onto a php page in order to view my clilents' information?
thank you!

Joe