douxiapi4381 2012-03-21 23:04
浏览 48
已采纳

处理JavaScript,PHP和MSSQL中的反斜杠

Before I get anywhere with this post, let me make this clear, there is absolutely nothing I can change about the string I'm about to show you, it must stay as it is.

I need to find some way of parsing a string without any escaping mechanisms. I have this string: "A2&11203[3\813+!5>di" which is used by this program I'm forced to deal with.

SQL parses that string just fine (backslash and all), but JavaScript and PHP keep using it as an escaping mech and removing the number 8.

What happens in my application is it receives that string and then using JavaScript, redirects to a webpage along with the string, the problem here is the backslash is being removed, which I must have.

I found this code in another stackoverflow post, and it works for what I need, but I need to stop JavaScript (and eventually PHP) from removing the backslash.

function post_to_url(path, params, method) {
    method = method || "post"; // Set method to post by default, if not specified.

    // The rest of this code assumes you are not using a library.
    // It can be made less wordy if you use one.
    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for(var key in params) {
        if(params.hasOwnProperty(key)) {
            var hiddenField = document.createElement("input");
            hiddenField.setAttribute("type", "hidden");
            hiddenField.setAttribute("name", key);
            hiddenField.setAttribute("value", params[key]);

            form.appendChild(hiddenField);
         }
    }

    document.body.appendChild(form);
    form.submit();
}

The string needs to be processed completely raw, i just checked the database and there are several cases with multiple backslashs everywhere along with damn near any character you can find on an english keyboard.

Any ideas as to what I can do about this issue? I'm forced to use JavaScript as the main redirector.

  • 写回答

2条回答 默认 最新

  • dsaj20411 2012-03-26 22:23
    关注

    With no way to properly escape backslashes, we changed to passing 4 other fields that would identify the account and then pulled the accountno within php, no more need to escape anything.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题