CodeIgniter框架URL支持中文的方法


PHP #codeigniter #框架 #url #中文2012-04-14 23:38
CodeIgniter默认的配置里,如果url含有中文则会提示 The URI you submitted has disallowed characters.


以下是解决方法:


在application/libraries/下增加一个文件MY_URI.php,其内容为:

class MY_URI extends CI_URI {
        function _filter_uri($str)
    {
        if ($str != ” AND $this->config->item(’permitted_uri_chars’) != ”)
        {
            $str = urlencode($str);  // 注意这里
            if ( ! preg_match(”|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i”, $str))
            {
                exit(’The URI you submitted has disallowed characters.’);
            }
            $str = urldecode($str);  // 注意这里
        }
        return $str;
    }
}


把$config['permitted_uri_chars'] = ‘a-z0-9~%.:_\-’;改成$config['permitted_uri_chars'] = ‘a-z 0-9~%.:_\+\-’;

相关文章

粤ICP备11097351号-1