php – $_POST在utf-8字符上为空

发布时间:2022-04-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了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输出请求.

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:
调试时,我发现System.core.Input类清除了_clean_input_data函数输入数据.

// 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
删除链接:EllisLabs已将此回购关闭公众

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

ini_set(‘default_charset’,’UTF-8′);

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

脚本宝典总结

以上是脚本宝典为你收集整理的php – $_POST在utf-8字符上为空全部内容,希望文章能够帮你解决php – $_POST在utf-8字符上为空所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。