$ _POST在utf-8字符上为空

Oza*_*zay 8 php codeigniter character-encoding

我正在使用CodeIgniter开发一个多语言网站.有一个表单将数据发布到控制器,但是$_POST当我开始使用土耳其字符öçüÜ?等时它是空的.

我将charset设置为:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Run Code Online (Sandbox Code Playgroud)

形成:

<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>
Run Code Online (Sandbox Code Playgroud)

$_POST$this->input->post('editor_tr')返回空,但我可以看到原始帖子file_get_contents("php://input").

这个在普通的PHP测试中正常工作,但不适用于CodeIgniter.也许我的.htaccess文件导致了这个问题,但不知道.

任何帮助深表感谢.

更新:这是var_dump的请求输出.

var_dump($_POST) - 没有土耳其字符

array(3) { ["id"]=> string(12) "news8titleID" ["editor_tr"]=> string(13) "turkish value" ["editor_en"]=> string(13) "english value" }
Run Code Online (Sandbox Code Playgroud)

var_dump($_POST)- 使用土耳其字符(输入为:Türkçe karakter,但它没有显示在$ _POST中)

array(3) { ["id"]=> string(12) "news8titleID" ["editor_tr"]=> string(0) "" ["editor_en"]=> string(13) "english value" }
Run Code Online (Sandbox Code Playgroud)

更新2: 调试时,我发现system.core.Input该类清除了_clean_input_data函数的输入数据.

// Clean UTF-8 if supported
if (UTF8_ENABLED === TRUE)
{
    $str = $this->uni->clean_string($str);
}
Run Code Online (Sandbox Code Playgroud)

因此,在$_POST到达我的控制器之前,该函数中editor_trsystem.core.Utf8类已经清除了该值:

function clean_string($str)
{
    if ($this->_is_ascii($str) === FALSE)
    {
        $str = @iconv('UTF-8', 'UTF-8//IGNORE', $str);
    }

    return $str;
}
Run Code Online (Sandbox Code Playgroud)

Wes*_*rch 6

由于评论堆积如山,可能会被忽视,我将发布更多建议.

读者请记住,这是处理$ _POST数据值而不是在网页上显示数据.

这个用户似乎有类似的问题:

Codeigniter似乎打破了'£'字符的$ _POST(磅)

这里有关于Bitbucket的类似报告:

https://bitbucket.org/ellislab/codeigniter-reactor/issue/214/problem-when-inserting-special-characters:已 删除的链接:EllisLabs已将此回购已关闭给公众

也许将它添加到index.php会有所帮助(可能不会):

ini_set('default_charset', 'UTF-8');

仔细检查并确保您没有在该字段上运行任何验证或准备规则.这样的事情url_title()会剥夺那些角色.


小智 6

确保表单标记具有accept-charset:

<form method="post" action="" accept-charset="utf-8">
Run Code Online (Sandbox Code Playgroud)

然后在控制器中使用utf8_decode()获取发布的值:

$value = utf8_decode($this->input->post('field_name'));
Run Code Online (Sandbox Code Playgroud)