Hi,
I have been doing research on this as well and found a solution that does not involve fiddlin with the CI standard files.
Create the following helper in your system/application/helpers folder:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Rewrite all outgoing text into UTF8 compatible streams
* Author: Matt Carter <[email protected]>
* Info: <a href="http://hash-bang.net/2009/02/utf8-with-codeigniter">http://hash-bang.net/2009/02/utf8-with-codeigniter</a>
*/
function ob_utf8($string) {
return utf8_decode($string);
}
ob_start('ob_utf8');
foreach ($_POST as $key => $val) // Re-write all incoming text into UTF8 streams
$_POST[$key] = utf8_encode($val);
?>Then simply add it to your system/application/autoload.php:
$autoload['helper'] = array('utf8');The helper will automatically convert incoming POST data into MySQL compatible UTF8 and convert outgoing text into HTML UTF8 streams. No need for
mysql_query(“SET NAMES ’utf8’”);
This worked wonders for me, and is now my first step for any new project in CI.
I hope this helps 😉
Source: http://hash-bang.net