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 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化