ASP tutorial filtering HTML-sensitive characters into HTML-encoded functions
' This function is based on the user's incoming parameters and then traversing the HTML-sensitive characters into HTML-encoded form, which filters sensitive HTML.
function Htmlencode2 (str)
Dim result
Dim l
If IsNull (str) Then
Htmlencode2= ""
Exit function
End If
L=len (str)
Result= ""
Dim i
For i = 1 to L
Select Case Mid (str,i,1)
Case "<"
result=result+ "<"
Case ">"
result=result+ ">"
Case Chr (13)
result=result+ "<br>"
Case Chr (34)
result=result+ """
Case "&"
result=result+ "&"
Case Chr (32)
' result=result+ ' '
If I+1<=l and i-1>0 then
If Mid (str,i+1,1) =CHR or mid (str,i+1,1) =CHR (9) or mid (str,i-1,1) =CHR (?) or mid (str,i-1,1) =CHR (9) Then
result=result+ " "
Else
Result=result+ ""
End If
Else
result=result+ " "
End If
Case Chr (9)
Result=result+ ""
Case Else
Result=result+mid (str,i,1)
End Select
Next
Htmlencode2=result
End Function
%>