Issue of wierd characters in a dynamic PHP web page

When using special characters in UTF-8 character encoding, sometimes when you read something from mysql database then it is not displayed properly on the web page. Many of you like me may try to change the character encoding of the HTML page to ISO-8859-1, that may work sometimes but this is not the proper solution to the problem.

Irrespective of the character encoding used by MySql to store the text data, when you query something using SQL it returns the data encoded in the latin charset. This is defined in the mysql config files, as described below:

The character_set_results system variable indicates the character set in which the server returns query results to the client. This includes result data such as column values, and result metadata such as column names.

To change the character encoding to UTF8 or other, you need to use “mysql_set_charset()” mysql function in PHP. Pass the correct encoding name required and now future mysql queries will return result using new encoding.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.