$ _POST空的utf-8字符 [英] $_POST empty on utf-8 characters

查看:172
本文介绍了$ _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文件是导致问题,但dunno。

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.

任何帮助是非常感激。

strong> UPDATE :
下面是请求的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 / code> - 使用土耳其语字符(输入为Türkçekarakter ,但它不会显示在$ _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" }

UPDATE 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:

​​代码似乎断开$ _POST的'£'字符(Pound)

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

There is a report here on Bitbucket of similar:

https://bitbucket.org/ellislab/codeigniter-reactor / issue / 214 /问题 - 插入特殊字符
已删除链接: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天全站免登陆