hey guys was hoping you could help me out.
I am required to make a website coded in php+codeigniter to work with utf 16 charset.
So to convert it,
I have converted the database.php settings to:
$db['default']['char_set'] = 'utf16';
$db['default']['dbcollat'] = 'utf16_unicode_ci';
I have made the config.php settings to:
$config['charset'] = 'UTF-16';
That seemed to solve the problem that was caused when outputing data, however I now have a new problem.
My form validation checks have started failing, particular the length one.
i.e when debugging I found that it was taking admin@admin.com as length 7 with the mb_strlen function.
note that it was working properly before the charset change! problem started after charset change.
update: turns out if you do mb_strlen($str,'utf-8') i get the correct answer, meaning that I am getting utf-8 encoded strings from the form.
changing the min_length function from
public function min_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
{
return FALSE;
}
if (function_exists('mb_strlen'))
{
return (mb_strlen($str) < $val) ? FALSE : TRUE;
}
return (strlen($str) < $val) ? FALSE : TRUE;
}
to this:
public function min_length($str, $val)
{
if (preg_match("/[^0-9]/", $val))
{
return FALSE;
}
if (function_exists('mb_strlen'))
{
echo $str,"<br/>";
echo mb_strlen($str),"<br/>";
echo $val;die();
return (mb_strlen($str) < $val) ? FALSE : TRUE;
}
return (strlen($str) < $val) ? FALSE : TRUE;
}
I get the following output:
admin@admin.com
7
8
i.e it is taking admin@admin.com as length 7!