Using UTF8 in applications

From ATK Wiki

Jump to: navigation, search

ATK Howto: Using UTF8 in applications

Complexity: Easy
Author: Jeroen van Sluijs

List of other Howto's



If you see strange characters in your application, like 'This is � special char', you probably use a non-utf8 charset. In this howto I will explain how to make a project with UTF-8 support.

3 simple steps


Make sure you create your database with 'MySQL connection collation:' set to 'utf8_unicode_ci', so each table has this collation type.

Add the following code to your

$config_db["default"]["charset"]  = "utf8";
$config_default_charset = "utf-8";

For each language you use, you'll have to set the 'charset' in the corresponing languagefile in atk/languages. Since it is not possible to commit these languagefiles in your project, you can solve this as follows:

Add this code to a to override the 'charset' in your languagefile (in the global scope, not in a function!):

 $lang = atkinstance("atk.atklanguage");
 $lang->setText("charset", "utf-8", "en");
 $lang->setText("charset", "utf-8", "nl");

The is always loaded, to these settings will apply to the complete application.


After reloading your website, you should see the Unicode (UTF-8) option selected (in firefox: View > Character Encoding).

Personal tools