lemmin Posted June 20, 2008 Share Posted June 20, 2008 I am trying to escape single and double quotes and I have come across the strangest anomalies. I can get each to escape in separate cases, but never together. Here is what I mean; If the outer-most quotes are single and the inner ones are double, double quotes will escape but not single quotes: //This works: onMouseOver='self.status="te\"st";' //But this doesn't: onMouseOver='self.status="te\'st";' Similarly, if the outer-most quotes are double and the inner ones are single, single quotes will escape but not double quotes: //This works: onMouseOver="self.status='te\'st';" //But this doesn't: onMouseOver="self.status='te\"st';" However, if I only use one set of qoutes everything works as expected, but it seems strange to not have the event code in quotes: //This works: onMouseOver=self.status="te\"\'st"; Is there anyway to get both types of quotes to escape inside tiered quotes? If not, should I be worried about not putting the event code in quotes as the last code example shows? Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/111141-escaping-single-and-double-quotes/ Share on other sites More sharing options...
Psycho Posted June 20, 2008 Share Posted June 20, 2008 It makes perfect sens to me. I think you are confusing the parameter value and a string value. You don't escape quortes for the paramater, but you do for the string. Here is one of the examples where you say it doesn't work: Here is the parameter value: onMouseOver="self.status='te\"st';" Here is the string value: onMouseOver="self.status='te\"st';" It is defined with single quotes, so any single quotes in the string must be escaped. Link to comment https://forums.phpfreaks.com/topic/111141-escaping-single-and-double-quotes/#findComment-570658 Share on other sites More sharing options...
lemmin Posted June 23, 2008 Author Share Posted June 23, 2008 I understand what the string is. I want to be able to put a quote character in the string, but the method I found to allow me to this disallows me to use a single quote character in the string, likewise, the other way around is a problem, too. In the example you provided, how would I make a double quote show up in the status bar? Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/111141-escaping-single-and-double-quotes/#findComment-572306 Share on other sites More sharing options...
Psycho Posted June 23, 2008 Share Posted June 23, 2008 Just use the HTML character code(s): <html> <Head></head> <body> <div onMouseOver="self.status='A test with (\') single quote.';">This shows a single quote</div><br> <div onMouseOver="self.status='A test with (") double quote.';">This shows a double quote</div><br> <div onMouseOver="self.status='A test with (\') (") both quotes.';">This shows both quote makrs</div><br> </body> </html> Link to comment https://forums.phpfreaks.com/topic/111141-escaping-single-and-double-quotes/#findComment-572441 Share on other sites More sharing options...
lemmin Posted June 23, 2008 Author Share Posted June 23, 2008 Thanks, that would be a good solution, but I was curious if there was actually a way to make the escaping work as expected. It seems strange to me that it is only possible to escape one or the other. I figured there was a different syntax than the way I was doing it that would allow normal escaping of those characters. Thanks for the help. Link to comment https://forums.phpfreaks.com/topic/111141-escaping-single-and-double-quotes/#findComment-572490 Share on other sites More sharing options...
Psycho Posted June 23, 2008 Share Posted June 23, 2008 I hear what you're saying. I thought thre was a way to escape the outer quotes as well. But I wasn't able to figure out a solution after several minutes of testing. So, as long as there is an acceptable solution I wouldn't waste too much time trying to figure it out. Link to comment https://forums.phpfreaks.com/topic/111141-escaping-single-and-double-quotes/#findComment-572548 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.