Using UTF8 in applications
From Achievo/ATK Wiki
|
ATK Howto: Using UTF8 in applications
|
Contents |
Intro
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
Database
Make sure you create your database with 'MySQL connection collation:' set to 'utf8_unicode_ci', so each table has this collation type.
config.inc.php
Add the following code to your config.inc.php:
$config_db["default"]["charset"] = "utf8"; $config_default_charset = "utf-8";
module_preload.inc
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 module_preload.inc to override the 'charset' in your languagefile (in the global scope, not in a function!):
<?php
$lang = atkinstance("atk.atklanguage");
$lang->setText("charset", "utf-8", "en");
$lang->setText("charset", "utf-8", "nl");
?>
The module_preload.inc is always loaded, to these settings will apply to the complete application.
Checking
After reloading your website, you should see the Unicode (UTF-8) option selected (in firefox: View > Character Encoding).