ldsmike88 Posted March 12, 2007 Share Posted March 12, 2007 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 More sharing options...
ldsmike88 Posted March 12, 2007 Author Share Posted March 12, 2007 I gave up on trying to addslashes in javascript. Instead I just used addslashes(addslashes($myVar)); in php. Sorry for the unnecessary post. Michael Link to comment https://forums.phpfreaks.com/topic/42413-solved-addslashes-in-javascript/#findComment-205750 Share on other sites More sharing options...
fenway Posted March 13, 2007 Share Posted March 13, 2007 You can write a very simple escape function for quotes. Link to comment https://forums.phpfreaks.com/topic/42413-solved-addslashes-in-javascript/#findComment-206501 Share on other sites More sharing options...
ldsmike88 Posted March 13, 2007 Author Share Posted March 13, 2007 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; } Link to comment https://forums.phpfreaks.com/topic/42413-solved-addslashes-in-javascript/#findComment-206541 Share on other sites More sharing options...
fenway Posted March 14, 2007 Share Posted March 14, 2007 That is strange... at least for stripslashes, there are some missing backslashes. Link to comment https://forums.phpfreaks.com/topic/42413-solved-addslashes-in-javascript/#findComment-207111 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.