编码食谱/HTML 编码
外观
< 编码食谱
将对象(通常是字符串)转换为 HTML 安全代码。
可以转换字符串和记录集(转换为表格)。
function HTMLEncode (vInput) dim i if IsNull(vInput) then HTMLEncode = vInput exit function end if select case TypeName(vInput) case "Recordset" HTMLEncode = _ "<table border='1'>" & vbNewLine & _ " <tr>" for i = 0 to vInput.Fields.Count - 1 HTMLEncode = HTMLEncode & "<th>" & HTMLEncode(vInput.Fields.Item(i).Name) & "</th>" next HTMLEncode = HTMLEncode & "</tr>" & vbNewLine if not vInput.BOF then vInput.MoveFirst while not vInput.EOF HTMLEncode = HTMLEncode & " <tr>" for i = 0 to vInput.Fields.Count - 1 if IsNull(vInput.Fields.Item(i).Value) then HTMLEncode = HTMLEncode & "<td> </td>" else HTMLEncode = HTMLEncode & "<td>" & HTMLEncode(vInput.Fields.Item(i).Value) & "</td>" end if next HTMLEncode = HTMLEncode & "</tr>" & vbNewLine vInput.MoveNext wend if not vInput.BOF then vInput.MoveFirst HTMLEncode = HTMLEncode & _ "</table>" & vbNewLine case else HTMLEncode = vInput HTMLEncode = Replace(HTMLEncode, chr(0), "") HTMLEncode = Trim(Server.HTMLEncode(HTMLEncode)) HTMLEncode = Replace (HTMLEncode, "'", "'") HTMLEncode = Replace (HTMLEncode, "<", "<") HTMLEncode = Replace (HTMLEncode, ">", ">") HTMLEncode = Replace (HTMLEncode, " ", " ") HTMLEncode = Replace (HTMLEncode, chr(10), "<br>" ) end select end function