Reputation: 302
I have inherited an elderly Codeigniter 1.0 site with German language content. Arg.
It was running on a server with php 5.2 and MySQL 5.0.
Updating the server to use php 5.4 and MySQL 5.5 caused the character encoding to fall to bits - I assume Codeigniter is running the database content (which is correct) through some sort of filter.
It now shows, for example, ü where the database has ü
Everything is set to UTF-8, and nothing on the site itself has changed, although the database has been updated of course.
Any ideas where I could look to find out where this is happening and give it a stern talking to? Please use small words if you have a suggestion, because I don't know codeigniter very well. :-D
EDIT1
I have the charset in the HTML set to utf-8 - that hasn't changed.
All the tables have collation : utf8_unicode_ci
in config/database.php, I have:
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
EDIT2
As suggested by Chococroc, I created a test php file to pull the data direct from the database. This displayed the German characters correctly, but helped me to realise that in the database, HTML is being stored as HTML entities - <p>
instead of <p>
for example.
Could it be that whatever is turning these entities back into HTML is also mangling the German characters...?
Upvotes: 2
Views: 983
Reputation: 1680
Codeigniter have utf-8 character input data save issue in some hosting servers like Etisalat. system/core/Utf8.php have function to detect illegal char in input data(post/get). In some cases utf-8 char is consider as illegal and save function will fail. For avoid data saving issue do the following in clean_string() function of Utf8.php at line 85.
$str = !mb_detect_encoding($str, 'UTF-8', TRUE) ? utf8_encode($str) : $str;
$str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
Upvotes: 0
Reputation: 15892
Ok, so you checked all in CodeIgniter config charset and UTF-8 support, well, let's dive into CI, according to this post: http://www.jamipietila.fi/codeigniter-and-utf-8/ there are three places to look into:
Config.php
$config['charset'] = "UTF-8";
Database.php
$db['default']['char_set'] = "utf8";
$db['default']['dbcollat'] = "utf8_general_ci";
Controllers: Add this line
$this->output->set_header('Content-Type:text/html; charset=UTF-8');
Last try if nothing works: If after ALL of this, it's still not working, check with a simple PHP file with a PDO to go to the DDBB and retrieve and output the results. If with that the utf-8 works, it's sure is something INSIDE CI. If not, it's your server, something that it doesn't like when you changed to PHP 5.4
Upvotes: 2