Server.HTMLEncode definition and usage
The HTMLEncode method applies HTML encoding to a specified string. Mainly for safety reasons.
grammar
Server.HTMLEncode(string)
| parameter | describe |
|---|---|
| string | Required. The string to encode. |
Example
script:
<%response.write(Server.HTMLEncode("The image tag: <img>"))%>Output:
The image tag: <img>
Browser output:
The image tag: <img>
In the writing of asp backend, we often use server.htmlencode all the content input by the user, for example
username=server.htmlencode(request("username"))
Then enter the database again. For security reasons, what users input is the most unreliable.
Below is the custom function of htmlencode
The HTMLEncode() function is a custom function that not only encodes HTML symbols, but also encodes carriage return and line breaks, allowing the content entered in the text box to be output in the original display format.
function HTMLEncode(fString) fString = replace(fString, "&", "&") fString = replace(fString, """", """) fString = replace(fString, "'", "'") fString = replace(fString, ">", ">") fString = replace(fString, "< ", "<") fString = replace(fString, "", " ") fString = replace(fString, CHR(13), "") fString = replace(fString, CHR(10) & CHR(10), "<p>") fString = replace(fString, CHR(10), "<br />") HTMLEncode = fStringend function
Here you can add the code you need to replace.
HTMLDecode function: It is the inverse function of HTMLEncode function. It displays characters in HTML as is in textarea, which is very useful when modifying information.
function HTMLDecode(fString) fString = replace(fString,">",">") fString = replace(fString,"<","<") fString = Replace(fString," ",chr(32)) fString = Replace(fString,""",chr(34)) fString = Replace(fString,"'",chr(39)) fString = Replace(fString,"",CHR(13)) fString = Replace(fString,"</P><P>",CHR(10)& CHR(10)) fString = Replace(fString,"<BR>",CHR(10)) HTMLDecode = fString
This is the article about the usage of Server.HTMLEncode in ASP (with custom functions). For more related asp HTMLEncode content, please search for previous articles of the Wrong New Webmaster Site or continue browsing the related articles below. I hope everyone will support the Wrong New Webmaster Site in the future!