CodeIgniter and UTF-8 Support

I am working on a site that uses / stores accented characters in a database. I have a page template installed so that the charset config.php variable matches this parameter, for example:

<meta charset="<?php echo $this->config->item('charset');?>">

The problem that I encountered is that if $config['charset']installed in UTF-8 , form validation fails, and as if no character was sent, a character with an accent was added. So, for example, a required field will be returned if it is included in the string. The line minus á works fine.

I managed to get this working by changing $config['charset']to ISO-8859-1 and converting the text to UTF-8 before pasting / after retrieving from the database using php utf8_encode()and utf8_decode(). Is this the best way or am I missing something necessary to get UTF-8 with accented characters working in CodeIgniter?

Any advice is appreciated.

+5
source share
1 answer

You need to make sure that you use UTF-8 everywhere, and that PHP and MySQL are configured to handle UTF-8.

In html add a meta tag:

<meta charset="utf-8" />

And save it in UTF-8 format. here's how to do it in notepad ++ .

Define MySQL tables to support UTF-8, create a table using

DEFAULT CHARSET=utf8;

And establish a connection with:

mysql_set_charset('utf8', $con);

UTF-8 php.ini:

default_charset = "utf-8"

Unicode -

+12

All Articles