php – $_POST在utf-8字符上为空
我正在使用CodeIgniter开发一个多语言网站.有一个表单将数据发布到控制器,但当我开始使用土耳其字符如??üü?等时,$_POST为空.
我将charset设置为: <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 形成: <form action="translations/save" method="post" accept-charset="utf-8"> <textarea rows="6" cols="60" id="editor_tr" name="editor_tr">Türk?e</textarea> </form> $_POST和$this-> input-> post(‘editor_tr’)返回空,但我可以看到带有file_get_contents(“php:// input”)的原始帖子. 这个在普通的PHP测试中运行正常,但不适用于CodeIgniter.也许我的.htaccess文件导致问题,但不知道. 任何帮助深表感谢. 更新: var_dump($_ POST) – 没有土耳其语字符 array(3) { ["id"]=> string(12) "news8titleID" ["editor_tr"]=> string(13) "turkish value" ["editor_en"]=> string(13) "english value" } var_dump($_ POST) – 使用土耳其字符(输入为:Türk?ekarakter,但它没有显示在$_POST中) array(3) { ["id"]=> string(12) "news8titleID" ["editor_tr"]=> string(0) "" ["editor_en"]=> string(13) "english value" } 更新2: // Clean UTF-8 if supported if (UTF8_ENABLED === TRUE) { $str = $this->uni->clean_string($str); } 所以,在$_POST到达我的控制器之前,这个函数中的system.core.Utf8类已经清除了editor_tr值: function clean_string($str) { if ($this->_is_ascii($str) === FALSE) { $str = @iconv('UTF-8','UTF-8//IGNORE',$str); } return $str; }
由于评论堆积如山,可能会被忽视,我将发布更多建议.
读者请记住,这是处理$_POST数据值而不是在网页上显示数据. 这个用户似乎有类似的问题: Codeigniter seems to break $_POST of ‘£’ character (Pound) 这里有关于Bitbucket的类似报告: https://bitbucket.org/ellislab/codeigniter-reactor/issue/214/problem-when-inserting-special-characters: 也许将它添加到index.php会有所帮助(可能不会): ini_set(‘default_charset’,’UTF-8′); 仔细检查并确保您没有在该字段上运行任何验证或准备规则. url_title()之类的东西会剥离这些字符. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |