是否有人知道max_lengthn和min_lengthn函数中内置的codeigniter表单验证是将unicode字符算作1个字符,还是将使用的所有字符的总和符号化unicode字符?
我注意到当我var_dump字符串时,它会计算所有的字符,只是想知道code igniter或php是否有一个内置的函数来计算unicode字符?
谢谢。
发布于 2012-08-02 23:46:00
Codeigniter使用php的mb_strlen,如果它在你的php安装中可用,允许传递一个编码参数,否则它默认使用php的基本strlength,这不允许你传递字符串编码。问题是,CI不能让您传递max_lengthn的可能编码……
如果您需要它来补偿编码,那么使用原始php进行自己的验证可能会更好。
发布于 2012-08-02 23:52:00
您可以进行自己的回调验证:
$this->form_validation->set_rules('rule', 'The rule', 'callback_checkUnicode');和选中unicode string>
public function checkUnicode($string)
{
if (strlen($string) != strlen(utf8_decode($string)))
{
//is unicode: add your own counter condition here
return true;
}
return false
}https://stackoverflow.com/questions/11780997
复制相似问题