[removed] A BackSlash as part of the string

后端 未结 3 809
无人及你
无人及你 2020-11-27 08:17

I have a JavaScript variable that I echo out using PHP which is shown like this in the page source:

var db_1 = \'C:\\this\\path\';

When I s

相关标签:
3条回答
  • 2020-11-27 08:30

    A backslash is an escape character in JS. They are lost when the string literal is parsed.

    You can't put them back, because you have no way of telling where they were. You have to make sure they remain in the string in the first place (by representing them with an escape sequence).

    var db_1 = 'C:\\this\\path';
    
    0 讨论(0)
  • 2020-11-27 08:37

    You can use:

    echo json_encode('C:\this\path');
    

    json_encode can be used as a filter function for some JavaScript code.

    0 讨论(0)
  • 2020-11-27 08:37

    Try this:

    var db_1 = 'C:\\this\\path';
    

    For more info: http://www.w3schools.com/js/js_special_characters.asp

    0 讨论(0)
提交回复
热议问题