Jump to content

[SOLVED] addslashes in javascript


ldsmike88

Recommended Posts

I have a string in php that contains "member's." Before I pass the variable to javascript I use addslashes to fix any problems I would have with it. The problem is when the string gets to the javascript, the javascript writes the string to the page without the backslash. How do I correct this problem? Thanks!

 

Michael

Link to comment
https://forums.phpfreaks.com/topic/42413-solved-addslashes-in-javascript/
Share on other sites

Well I found a addslashes and stripslashes function online but the addslashes doesn't seem to work at all and the stripslashes doesn't seem to work with double quotes " . Do you know why these don't work correctly?

 

function addslashes(str) {
str=str.replace(/\'/g,'\\\'');
str=str.replace(/\"/g,'\\"');
str=str.replace(/\\/g,'\\\\');
str=str.replace(/\0/g,'\\0');
return str;
}
function stripslashes(str) {
str=str.replace(/\\'/g,'\'');
str=str.replace(/\\"/g,'"');
str=str.replace(/\\\\/g,'\\');
str=str.replace(/\\0/g,'\0');
return str;
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.