Handling Hungarian character set from PHP – Ő Ű problem

I have started to write an app in php and run into the good old character set problem.Ő and Ű characters were not displayed correctly however I have converted the data back and forth. The key is to use UTF-8 encoding.

You have to tell php what encoding to use you can achieve this either using the HTML or the PHP definition. Whichever suits you. Add this to the header section of the HTML code:

<meta http-equiv=”content-type” content=”text/html; charset=UTF-8″ >

You can achieve the same using the header php command:

header(“Content-Type: text/html; charset=utf-8”);

Now we have to make sure that the data coming from the mysql database is UTF-8 encoded. Add this right after the database connection line.

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die (‘Error connecting to mysql’); // Add UTF-8 converting after this line
mysql_query(“SET NAMES UTF8”);

Make sure that the php file itself is saved from the editor in UTF-8 format. Each progamming editor has the capability to change the character encoding.

Finally check your database if  the tables and the database are utf8_hungarian_ci encoded. MySQL connection collation should be set to utf8_general_ci.

That should be it 🙂

2 thoughts on “Handling Hungarian character set from PHP – Ő Ű problem

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.