While working with UTF-8 in my application, these are all the places I've had to configure to work correctly:
- Add the following line to prepend.inc:
public static $EncodingType = 'UTF-8';
- The DB needs to store the data as UTF-8
- When connecting to the DB, the connection needs to support UTF-8. In particular, you need to add 'encoding' => 'utf8' to your DB Connection array if you use MySQL. Sample (in configuration.inc):
define('DB_CONNECTION_1', serialize(array( 'adapter' => 'MySqli5', 'server' => 'localhost', 'port' => null, 'database' => 'mydatabase', 'username' => 'root', 'password' => 'password', 'profiling' => false, 'encoding' => 'utf8' ))); - Alternative option is to add this line to prepend.inc:
if (QApplication::$EncodingType == 'UTF-8') { QApplication::$Database[1]->NonQuery("SET NAMES 'utf8'"); } - Your pages must have a Content-Type meta tag with charset=UTF-8
- If you have accented characters in your code, your php/html files must be saved in UTF-8 format (notepad can do this).
- Several common functions in PHP 5.2 lack unicode support, causing them to work improperly. There are custom function work-arounds posted on the php.net function pages. Be wary of all PHP string functions for versions < 5.3
- strlen()
- substr()
- must call htmlentities with additional parameters: htmlentities('mystring', ENT_COMPAT, UTF-8)
- QApplication::HtmlEntities? does this automatically
Once that was all done, everything seems to work, be self-consistant, and the accented characters show up with my DB tools, etc.
(authored by VexedPanda?)
