当前位置: 代码迷 >> ASP >> 类似论坛的回复的字符串的处理
  详细解决方案

类似论坛的回复的字符串的处理

热度:166   发布时间:2012-10-15 09:45:24.0
求助类似论坛的回复的字符串的处理
比如回复<script>alert('hello')</script>,还是显示这个而不执行脚本,求具体的处理办法或者函数

------解决方案--------------------
将 < > 这些符号 转为实体

http://www.w3school.com.cn/html/html_entities.asp
------解决方案--------------------
使用replace 字符串替换函数
http://qingxinxz.tk/newindex/content.asp?id=31
例如:
<%
function transfer(x)
x=replace(x,chr(13),"")
x=replace(x,chr(10)&chr(10),"<br ><br>")
x=replace(x,chr(10),"<br>")
x=replace(x,"<%" ,"&lt;%")
x=replace(x,"<","&lt;")

transfer=x
end function

%>
------解决方案--------------------
VBScript code

Function switchHtml(Strings, Mark)
    If Mark = 1 Then '//标签 转换成 HTML符号
        Strings = Replace(Strings, "<", "&lt;")
        Strings = Replace(Strings, ">", "&gt;")
        Strings = Replace(Strings, Chr(39), "&curren;")
        Strings = Replace(Strings, "'", "&curren;")
        Strings = Replace(Strings, "&acute;", "&curren;")
        Strings = Replace(Strings, Chr(34), "&quot;")
        switchHtml = Strings
    ElseIf Mark = 2 Then '//HTML符号 转换成 标签
        Strings = Replace(Strings, "&lt;", "<")
        Strings = Replace(Strings, "&gt;", ">")
        Strings = Replace(Strings, "&curren;", "'")
        Strings = Replace(Strings, "&quot;", Chr(34))
        switchHtml = Strings
        End If
End Function 
  相关解决方案