Note that there are some explanatory texts on larger screens.

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

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload