x
 
Create New Page
 View Previous Changes    ( Last updated by Brendon Carr )

Switching EE to Use UTF-8 Charset

Changes are made at your own risk and are not guaranteed to work. Always make backups of the database and files prior to implementing hacks. Make a special backup of the file and/or template you are modifying so that you can roll back quickly.

Hacks are dangerous and can cause your site to stop working. They make later updates to ExpressionEngine more difficult; you should track your hacks for post-update re-implementation. 

Most hacks are unnecessary, please review the Development Documentation for information on expanding ExpressionEngine via Modules, Extensions, and Plugins.

Hacks are never officially supported.

Note: ExpressionEngine 1.x supports the UTF-8 Charset with front end development out of the box. In other words, you can run your site perfectly in UTF-8 with no hacks. These instructions should only be used if you need EE to write your data to the database in the UTF-8 Charset. By default EE 1.x writes to the db with PHP’s default client character set, which is typically iso-8859-1. This “hack” provides instructions to modify that to UTF-8.

To switch a latin1 database to UTF-8 follow these steps:

Prerequisites: I (supersusie) was using MySQL 5, PHP 5, and EE 1.6.  You can probably use earlier versions, but PHP 4.2.2 and MySQL 4.1 are probably as low as you want to go.

# Create a copy of the original latin1 (ISO-8859-1) database.

# The new EE database needs to have all its tables converted to UTF-8.
  I tried to use the convert script from the forums, but it didn’t work.
  http://expressionengine.com/forums/viewthread/35716/
 
  So I got a database-y friend to help.  You may have another way to do this, like the one listed on this page: http://www.abcseo.com/papers/utf8-expression-engine.htm

# Make sure every template you serve has been set to use UTF-8 in the meta tag. It’s easiest if you do this using the system variable set in the General Configuration panel.

<meta http-equiv="Content-Type" content="text/html; charset={charset}" /> 

# Turn the site off at the General Configuration page; switch to UTF-8 at the same time
  https://www.example.com/system/index.php?S=0&C=admin&M=config_mgr&P=general_cfg

# Change the connection to use the new database in the config.php file

 

# Change the setting of each Weblog to be set to use UTF-8
  https://www.example.com/system/index.php?S=0&C=admin&M=blog_admin&P=blog_list

# Here’s the hack: The /system/db/db.mysql.php file should be edited to have this line, which ensures that the connection is UTF-8 specific:

At line 163-165 of the /system/db/db.mysql.php file, locate the code below:

$this->server_info = @mysql_get_server_info();

        return 
TRUE

Replace with the following content, which will comprise new lines 163-168:

$this->server_info = @mysql_get_server_info();

        
// ADD THIS to allow utf-8 character set connection between EE and MySQL
        
mysql_query("SET NAMES 'utf8'");        

        return 
TRUE

Note: Only the line under the comment “// ADD THIS…” is new content.

See this article for some additional changes that might be needed. 

# If your Web server is serving your files with a http header that specifies ISO-8859-1, then you need to override that.  Modify the .htaccess file with this line.  (Or otherwise ensure that your Web server is serving without any http charset header)

# Change the character set to UTF-8
   
AddDefaultCharset utf-

Category:HowTo
Category:Languages
Category:Tutorials
Category:Hacks

Category:EE1