$_POST 在 utf-8 字符上为空 [英] $_POST empty on utf-8 characters

查看:32
本文介绍了$_POST 在 utf-8 字符上为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm working on a multilingual site with CodeIgniter. There is a form that posts data to controller, but $_POST is empty when I start to use Turkish characters like öçüÜĞ etc.

我将字符集设置为:

<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").

$_POST and $this->input->post('editor_tr') returns empty, but I can see the raw post with file_get_contents("php://input").

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

This one works OK in a normal PHP test, but doesn't work with CodeIgniter. Perhaps my .htaccess file is causing the issue, but dunno.

非常感谢任何帮助.

更新:这是按要求提供的 var_dump 的输出.

UPDATE: Here is the output for var_dump as requested.

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

var_dump($_POST) - Without Turkish chars

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

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

var_dump($_POST) - With Turkish chars (The input was: Türkçe karakter, but it doesn't show up in the $_POST)

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

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

UPDATE 2: When debugging, I have found out that system.core.Input class cleans the input data on _clean_input_data function.

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

因此,在 $_POST 到达我的控制器之前,editor_tr 值已经被 system.core.Utf8 类在这个功能:

So, before the $_POST has reached to my controller, the editor_tr value is already cleaned by system.core.Utf8 class in this function:

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

    return $str;
}

推荐答案

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

Since the comments are piling up and will probably get overlooked, I am going to post some more suggestions.

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

Readers please keep in mind this is dealing with $_POST data values and not display of data on a web page.

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

This user seems to have a similar problem:

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

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

There is a report here on Bitbucket of similar:

https://bitbucket.org/ellislab/codeigniter-reactor/issue/214/problem-when-inserting-special-characters:已删除链接:EllisLabs 已向公众关闭此存储库

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

Maybe adding this to your index.php will help (probably not):

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

仔细检查并确保您没有在现场运行任何验证或准备规则.url_title() 之类的东西会去掉这些字符.

Double check and make sure you aren't running any validation or prepping rules on the field. Things like url_title() will strip those characters.

这篇关于$_POST 在 utf-8 字符上为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆