UTF-8 Encoding and Decoding

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
joesmithf1
Forum Newbie
Posts: 5
Joined: Sun Jul 16, 2006 5:17 pm

UTF-8 Encoding and Decoding

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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. :)
joesmithf1
Forum Newbie
Posts: 5
Joined: Sun Jul 16, 2006 5:17 pm

Post 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
Post Reply