【问题标题】:jQuery escape and UTF Contents problemsjQuery 转义和 UTF 内容问题
【发布时间】:2014-05-21 22:03:57
【问题描述】:

我正在使用 jQuery 提交一个表单 .. 为了管理 post() 我必须 escape() 一些文本区域.. 我的 jQuery 脚本:

    var dataString = 'title=' + escape(title) + '&auth=' + auth + '&mainImage=' + mainImage + '&art_text=' + escape(art_text) + '&language=' + language + '&tags=' + tags + '&Status=' + Status + '&postDate=' + datepicker;
    $.post("./Scripts/adminDoAddPost.php", dataString, function (data) {
        //do something
    });

现在当我得到数据时..我到达我的 php 脚本

虽然它应该显示为 من نحن

有没有办法解码整个字符串?

【问题讨论】:

  • 在 php 中获取数据后,您是否使用了例如urldecode($_GET['auth'])?还是html_entity_decode($_GET['auth'], null, 'UTF-8');
  • 由于某种原因,仅此一项并没有解决问题..用html_entity_decode(preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;", urldecode($_POST['art_text'])), null, 'UTF-8');修复它
  • 是的,对;你应该混合它们

标签: php jquery serialization decode


【解决方案1】:

你可以使用urldecodehtml_entity_decode作为

$str = preg_replace("/%u([0-9a-f]{3,4})/i","&#x\\1;",urldecode($_GET['whatever']));
$result = html_entity_decode($str,null,'UTF-8');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-09
    • 1970-01-01
    • 2013-11-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多