Jump to content

Replace " with '


ecluley

Recommended Posts

Hi, i have a piece of HTML code that is saved in a text file, then read back out and printed into an input box in a form. Unfortunatly, i assume, because of all the double quotes, this does not work and i get the html being executed on the page as if it were standard HTML. I then tried to replace double quotes in a string with single ones. my code was thus:(assume that var1 = <object width="425" height="350"><param name="movie" value="http://www.youtube.com/watch?v=aOJs_3SvsmM"></param><param'>http://www.youtube.com/watch?v=aOJs_3SvsmM"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/watch?v=aOJs_3SvsmM" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>)

response.write(replace(var1, """, "'"))

I can see why this is going wrong but is there a way of doing this so that it works.ThanksEwen

Link to comment
Share on other sites

Did you try writing the code in <textarea>. it might be easier. Try this.

<textarea rows="4" cols="100"><object width="425" height="350"><param name="movie" value="http://www.youtube.com/v/aOJs_3SvsmM"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/v/aOJs_3SvsmM" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object></textarea>

guess another option is to replace < with <. then it will display the HTML code.

Link to comment
Share on other sites

unfortunatly that didn't work. Basically the probelm is that i need it to remain dynamic, so the code i used was:

<textarea rows="4" cols="100"><% Response.write(var1) %></textarea>

var1 is defined in the text file as the big long html bitty: <object width="425" height="350"><param name="movie" value="http://www.youtube.com/watch?v=aOJs_3SvsmM"></param><param'>http://www.youtube.com/watch?v=aOJs_3SvsmM"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/watch?v=aOJs_3SvsmM" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>when i try the text area method, i get nothing at all.is there a way i can set up a loop to go through the string character at a time, finding " and replacing it with ' ?Cheers for the help and the quick response.Ewen

Link to comment
Share on other sites

Oh ok, think I understand the problem, its the ASP variable, when you assign a text like that to a variable. then the end of string will be an issue..... one way to handle this is to replace all the double quotes with single quote as soon as you get the string from the file, even before you assign the string to a variable.

Link to comment
Share on other sites

Hi, i have a piece of HTML code that is saved in a text file, then read back out and printed into an input box in a form. Unfortunatly, i assume, because of all the double quotes, this does not work and i get the html being executed on the page as if it were standard HTML. I then tried to replace double quotes in a string with single ones. my code was thus:(assume that var1 = <object width="425" height="350"><param name="movie" value="http://www.youtube.com/watch?v=aOJs_3SvsmM"></param><param'>http://www.youtube.com/watch?v=aOJs_3SvsmM"></param><param name="wmode" value="transparent"></param><embed src="http://www.youtube.com/watch?v=aOJs_3SvsmM" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350"></embed></object>)
response.write(replace(var1, """, "'"))

I can see why this is going wrong but is there a way of doing this so that it works.ThanksEwen

HTMLEncode it instead:
<input type="text" name="something" value="<%=Server.HTMLEncode(var1)%>" />

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...