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 Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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; } Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.