Make ASP output does not support HTML syntax

Source: Internet
Author: User
Tags html tags
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.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.