Monday, May 13, 2024
 Popular · Latest · Hot · Upcoming
172
rated 0 times [  174] [ 2]  / answers: 1 / hits: 163020  / 15 Years ago, mon, april 20, 2009, 12:00:00

Does JavaScript have a built-in function like PHP's addslashes (or addcslashes) function to add backslashes to characters that need escaping in a string?



For example, this:




This is a demo string with
'single-quotes' and double-quotes.




...would become:




This is a demo string with
'single-quotes' and
double-quotes.



More From » string

 Answers
0

http://locutus.io/php/strings/addslashes/



function addslashes( str ) {
return (str + '').replace(/[\']/g, '\$&').replace(/u0000/g, '\0');
}

[#99671] Thursday, April 16, 2009, 15 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;