Using UTF8 in applications: Difference between revisions
No edit summary |
No edit summary |
||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
{{howto|Easy|[[Jeroen van Sluijs]] | {{howto|Easy|[[Jeroen van Sluijs]]}} | ||
== Intro == | == Intro == | ||
| Line 18: | Line 18: | ||
Add this code to a module_preload.inc to override the 'charset' in your languagefile (in the global scope, not in a function!): | 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 = atkinstance("atk.atklanguage"); | ||
$lang->setText("charset", "utf-8", "en"); | $lang->setText("charset", "utf-8", "en"); | ||
$lang->setText("charset", "utf-8", "nl"); | $lang->setText("charset", "utf-8", "nl"); | ||
?> | |||
The module_preload.inc is always loaded, to these settings will apply to the complete application. | The module_preload.inc is always loaded, to these settings will apply to the complete application. | ||
Latest revision as of 09:57, 11 March 2011
|
ATK Howto: Using UTF8 in applications
|
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).