Grammar sometimes we worry about such a problem, is how to avoid supporting HTML syntax in ASP pages.
For example: The following sentence
"<form><input type=text></form> This is a form statement"
When we output this phrase with Response.Write "<form><input type=text></form> This is a form statement" in the ASP file, a text box appears. Clearly this is a departure from our purpose.
To get the normal output: <form><input type=text></form> This is a form statement
We have to do a special deal with this string, there are 3 ways to achieve:
1. Direct use of ASP Syntax Server.HTMLEncode ()
Rstr= "<form><input type=text></form> This is a form statement"
Rstr=server.htmlencode (RSTR)
Response.Write Rstr
' Response statement output can be the correct result, but this method seems to produce garbled. The author has encountered this headache problem.
My homepage is placed in a foreign server, after using this method, all Chinese is garbled, and English is correct, but the server
It was obvious that they supported Chinese, so they thought of the 2nd method.
2. Use the Server.HTMLEncode () syntax only for characters other than Chinese in the string, as follows:
Rstr= "<form><input type=text></form> This is a form statement"
temp = ""
For i = 1 to Len (RSTR)
En = Mid (rstr,i,1)
if (ASC (EN) >40 and ASC (EN) <130) then Zh=server.htmlencode (en)
' Judge whether the character en is Chinese or not with Server.HTMLEncode ()
temp = temp + en
Next
Rstr= Temp
Response.Write Rstr
' The result is very correct and will not appear garbled. But this method is redundant, the processing speed is not fast, so there is a better 3rd method.
3. This is a special method, it can be said that the idea is very clever. We all know that HTML tags are "<" ">" combination, so as long as the two special characters to do special treatment, that is, "<" with "," ">" with "" "instead, This prevents the browser from supporting HTML syntax. The following statements are:
Rstr=replace (RSTR, "<", "the", 1)
Rstr=replace (RSTR, ">", ">", 1)
Response.Write Rstr
' This method is simple and clear, not only to the correct results, there will be no garbled, recommended use.