Multilanguage Programming with UTF-8 Encoding

Multilanguage non-ASCII site? Sometimes we need to make website that can handle languages which contains non-ASCII characters, for example chinese, russian, french, germany, etc.
To handle this, we need to handle the language on 3 parts : on PHP itself, HTML, and on the database (i use MySQL as example here).
Basically, we need to adjust the charset (character set) into UTF-8.

On PHP, the main task is to display non-ASCII characters correctly to the client. The key is the page encoding. If you use wrong encoding, characters will be displayed incorrectly such as question marks etc.
To do this, you can add this line on your PHP script

The code above will force browser encoding to UTF-8

On HTML, we can use UTF-8 encoding such as this

On database, now this is the final step especially if you want so save the characters into database. Now we will change table & column encoding into UTF-8.
You need to alter your varchar / text column encoding to “utf8_bin“.
Next, you should adjust your table default encoding to “utf8_bin” too.

ALTER TABLE your_table_name_here DEFAULT CHARACTER SET utf8 COLLATE utf8_bin


Leave a comment

Your email address will not be published. Required fields are marked *