asp 过滤html代码程序

Function TransferHTML(ByVal source,para)

 Dim objRegExp

 '先换"&"
 If Instr(para,"[&]")>0 Then  source=Replace(source,"&","&")
 If Instr(para,"[<]")>0 Then  source=Replace(source,"<","&lt;")
 If Instr(para,"[>]")>0 Then  source=Replace(source,">","&gt;")
 If Instr(para,"[""]")>0 Then source=Replace(source,"""","&quot;")
 If Instr(para,"[space]")>0 Then source=Replace(source," ","&nbsp;")
 If Instr(para,"[enter]")>0 Then
  source=Replace(source,vbCrLf,"<br/>")
  source=Replace(source,vbLf,"<br/>")
 End If
 If Instr(para,"[vbCrlf]")>0 Then

  Set objRegExp=New RegExp
  objRegExp.IgnoreCase =True
  objRegExp.Global=True

  objRegExp.Pattern="((</?form[^n<]*>)|(<select[^n<]*>)|(<textarea[^n<]*>)|(</?option[^n<]*>)|(</?dl[^n<]*>)|(</?dt[^n<]*>)|(</?dd[^n<]*>)|(</?th[^n<]*>)|(</?tr[^n<]*>)|(</?td[^n<]*>)|(</?tbody[^n<]*>)|(</?table[^n<]*>)|(</?hr[^n<]*>)|(</?div[^n<]*>)|(</?ul[^n<]*>)|(</?li[^n<]*>)|(</?ol[^n<]*>)|(</?h1[^n<]*>)|(</?h2[^n<]*>)|(</?h3[^n<]*>)|(</?h4[^n<]*>)|(</?h5[^n<]*>)|(</?h6[^n<]*>)|(</?p[^n<]*>))(x20*(rn|n))"

  source= objRegExp.Replace(source,"$1")

  objRegExp.Pattern="(rn|n)"
  source= objRegExp.Replace(source,"<br/>")

  source=Replace(source,"<html>","")
  source=Replace(source,"</html>","")
  source=Replace(source,"<body>","")
  source=Replace(source,"</body>","")

 End If
 If Instr(para,"[vbTab]")>0 Then source=Replace(source,vbTab,"&nbsp;&nbsp;")
 If Instr(para,"[no-asp]")>0 Then
  source=Replace(source,"<"&"%","&lt;"&"%")
  source=Replace(source,"%"&">","%"&"&gt;")
 End If
 If Instr(para,"[nofollow]")>0 Then
  source=Replace(source,"<a ","<a rel=""nofollow"" ")
 End If
 If Instr(para,"[nohtml]")>0  Then
  Set objRegExp=New RegExp
  objRegExp.IgnoreCase =True
  objRegExp.Global=True
  objRegExp.Pattern="<[^>]*>"
  source= objRegExp.Replace(source,"")
 End If
 If Instr(para,"[filename]")>0  Then
  source=Replace(source,"/","")
  source=Replace(source,"","")
  source=Replace(source,":","")
  source=Replace(source,"?","")
  source=Replace(source,"*","")
  source=Replace(source,"""","")
  source=Replace(source,"<","")
  source=Replace(source,">","")
  source=Replace(source,"|","")
  source=Replace(source," ","")
 End If
 If Instr(para,"[normalname]")>0  Then
  source=Replace(source,"$","")
  source=Replace(source,"(","")
  source=Replace(source,")","")
  source=Replace(source,"*","")
  source=Replace(source,"+","")
  source=Replace(source,",","")
  source=Replace(source,"[","")
  source=Replace(source,"]","")
  source=Replace(source,"{","")
  source=Replace(source,"}","")
  source=Replace(source,"?","")
  source=Replace(source,"","")
  source=Replace(source,"^","")
  source=Replace(source,"|","")
  source=Replace(source,":","")
  source=Replace(source,"""","")
  source=Replace(source,"'","")
 End If
 If Instr(para,"[textarea]")>0 Then
  source=Replace(source,"&","&amp;")
  source=Replace(source,"%","%")
  source=Replace(source,"<","&lt;")
  source=Replace(source,">","&gt;")
 End If
 If Instr(para,"[html-format]")>0 Then
  source=Replace(source,"&","&amp;")
  source=Replace(source,"<","&lt;")
  source=Replace(source,">","&gt;")
  source=Replace(source,"""","&quot;")
 End If
 If Instr(para,"[anti-html-format]")>0 Then
  source=Replace(source,"&quot;","""")
  source=Replace(source,"&lt;","<")
  source=Replace(source,"&gt;",">")
  source=Replace(source,"&amp;","&")
 End If
 If Instr(para,"[wapnohtml]")>0 Then
  source=Replace(source,"<br/>",vbCrLf)
  source=Replace(source,"<br>",vbCrLf)
  Set objRegExp=New RegExp
  objRegExp.IgnoreCase =True
  objRegExp.Global=True
  objRegExp.Pattern="(<[^>]*)|([^<]*>)"
  source= objRegExp.Replace(source,"")
  objRegExp.Pattern="(rn|n)"
  source= objRegExp.Replace(source,"<br/>")
 End If
 If Instr(para,"[nbsp-br]")>0 Then
  Set objRegExp=New RegExp
  objRegExp.IgnoreCase =True
  objRegExp.Global=True
  objRegExp.Pattern="&lt;$|&lt;b$|&lt;br$|&lt;br/$"
  source= objRegExp.Replace(source,"")
  objRegExp.Pattern="^br/&gt;|^r/&gt;|^/&gt;|^&gt;"
  source= objRegExp.Replace(source,"")
  objRegExp.Pattern="&lt;br/&gt;"
  source= objRegExp.Replace(source,"<br/>")
  objRegExp.Pattern="&amp;nbsp;"
  source= objRegExp.Replace(source," ")
 End If
 If Instr(para,"[closehtml]")>0 Then
  source=closeHTML(source)
 End If

 TransferHTML=source

End Function

时间: 2024-09-25 10:16:27

asp 过滤html代码程序的相关文章

asp ubb转换代码程序

function UBBCode(strContent,ctype)  on error resume next  if ctype=1 then  strContent = HTMLEncode(strContent)  else  strContent = strContent  end if  dim objRegExp  Set objRegExp=new RegExp  objRegExp.IgnoreCase =true  objRegExp.Global=True     if c

动态网页爱好者来看:Asp过滤HTML的函数

爱好者|动态|函数|网页 Asp过滤Html代码 Function RemoveHTML(strHTML) Dim objRegExp, Match, Matches Set objRegExp = New Regexp objRegExp.IgnoreCase = True objRegExp.Global = True '取闭合的<> objRegExp.Pattern = "<.+?>" '进行匹配 Set Matches = objRegExp.Exec

asp+的论坛列表程序---代码部分

asp+|程序 原作者: 雨晨asp+的论坛列表程序---代码部分 -------------------------------------------------------------------------------- [bigeagle] 于 2000-11-13 15:38:57 加贴在 Joy ASP ↑: /////////////////////////////////////////////////////////////////////////////// // // F

用asp实现的代码批量修改程序,fso相关

用asp实现的代码批量修改程序,fso相关 是因工作需要做的一个批量修改代码的小东西,拿出来与大家分享 目前可以处理的文件类型:.asp .inc .htm .html 具体类型可自行修改添加 程序实现的功能:将源目录下的文件批量修改后存到目的目录下 用它稍做修改可以实现很多东西噢! 别的不说了,代码里面都写的很清楚了 <% '// +---------------------------------------------------------------------------+ '//

用asp实现的代码批量修改程序

程序 用asp实现的代码批量修改程序,fso相关 是因工作需要做的一个批量修改代码的小东西,拿出来与大家分享 目前可以处理的文件类型:.asp .inc .htm .html 具体类型可自行修改添加 程序实现的功能:将源目录下的文件批量修改后存到目的目录下 用它稍做修改可以实现很多东西噢! 别的不说了,代码里面都写的很清楚了 <% '// +---------------------------------------------------------------------------+ '

用asp实现的代码批量修改程序,fso相关_FSO专题

用asp实现的代码批量修改程序,fso相关 是因工作需要做的一个批量修改代码的小东西,拿出来与大家分享 目前可以处理的文件类型:.asp .inc .htm .html 具体类型可自行修改添加 程序实现的功能:将源目录下的文件批量修改后存到目的目录下 用它稍做修改可以实现很多东西噢! 别的不说了,代码里面都写的很清楚了 <% '// +---------------------------------------------------------------------------+ '//

asp.net生成图形验证代码程序

asp教程.net生成图形验证代码程序 void palm::display() {     glloadidentity();                                 // 重置当前的模型观察矩阵     glcolor3f(.0f,1.0f,1.0f);        //绘制手掌四周     glbegin(gl_quad_strip);         glvertex3f(  -39.5000     ,     37.7987  ,   10.0000 ) ;

asp.net下载文件程序代码

asp.net下载文件程序代码 System.IO.FileInfo file = new System.IO.FileInfo(pstrFilePath); if (file.Exists) { Response.Clear(); Response.Charset = "GB2312"; Response.ContentEncoding = System.Text.Encoding.UTF8; Response.AddHeader("Content-Disposition&

asp获取搜索蜘蛛程序代码

asp获取搜索蜘蛛程序代码 Function GetSearcher(ByVal strUrl)  On Error Resume Next  If Len(strUrl) < 5 Then   GetSearcher = "DirectInput"   Exit Function  End If  If strUrl = ''Or InStr(strUrl, ":") = 0 Then   GetSearcher = "DirectInput&qu