程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> asp中實現清除html的函數

asp中實現清除html的函數

編輯:關於ASP編程

這個函數是必需要的,很多黑客來搗亂,黑掉數據庫,會注入大量的病毒js,在存儲和展示文本數據的時候,使用此函數過濾一下,可避免不少麻煩

clearhtml代碼

'清除HTML代碼
function clearhtml(content)
  content=replacehtml("&#[^>]*;","",content)
  content=replacehtml("</?marquee[^>]*>","",content)
  content=replacehtml("</?object[^>]*>","",content)
  content=replacehtml("</?param[^>]*>","",content)
  content=replacehtml("</?embed[^>]*>","",content)
  content=replacehtml("</?table[^>]*>","",content)
  content=replacehtml(" ","",content)
  content=replacehtml("</?tr[^>]*>","",content)
  content=replacehtml("</?th[^>]*>","",content)
  content=replacehtml("</?p[^>]*>","",content)
  content=replacehtml("</?a[^>]*>","",content)
  content=replacehtml("</?img[^>]*>","",content)
  content=replacehtml("</?tbody[^>]*>","",content)
  content=replacehtml("</?li[^>]*>","",content)
  content=replacehtml("</?span[^>]*>","",content)
  content=replacehtml("</?div[^>]*>","",content)
  content=replacehtml("</?th[^>]*>","",content)
  content=replacehtml("</?td[^>]*>","",content)
  content=replacehtml("</?script[^>]*>","",content)
  content=replacehtml("(javascript|jscript|vbscript|vbs):","",content)
  content=replacehtml("on(mouse|exit|error|click|key)","",content)
  content=replacehtml("<\\?xml[^>]*>","",content)
  content=replacehtml("<\/?[a-z]+:[^>]*>","",content)
  content=replacehtml("</?font[^>]*>","",content)
  content=replacehtml("</?h[^>]*>","",content)
  content=replacehtml("</?u[^>]*>","",content)
  content=replacehtml("</?i[^>]*>","",content)
  content=replacehtml("</?center[^>]*>","",content)
  content=replacehtml("</?center[^>]*>","",content)
  content=replacehtml("</?nobr[^>]*>","",content)
  content=replacehtml("</?clk[^>]*>","",content)
  content=replacehtml("</?muti[^>]*>","",content)
  content=replacehtml("</?/option[^>]*>","",content)
  content=replacehtml("</?o[^>]*>","",content)
  content=replacehtml("</?strong[^>]*>","",content)
  clearhtml=content
end function

replacehtml代碼

function replacehtml(patrn,strng,content)  
  if isnull(content) then
    content=""
  end if
  set regex=new regexp
  regex.pattern=patrn
  regex.ignorecase=true
  regex.global=true
  replacehtml=regex.replace(content,strng)
end function

使用方法:

復制代碼 代碼如下:
<%=clearhtml("<div id="CodeTip"><h2>分享代碼提示(2)</h2><ul><li style="font-weight: bold; color: rgb(170, 0, 0);">添加完代碼必須點擊“完成並查看”生效</li><li>准確的編程語言,可正確對代碼語法著色</li><li>輸入簡單幾個字的代碼片段說明</li><li>上傳源碼文件時無需再輸入說明</li><li>非程序相關文件將直接刪除,嚴重封帳號</li><li>圖片僅用來上傳截圖之類的文件,勿作他途</li></ul></div>")%>

以上就是本文所述的全部內容了,希望大家能夠喜歡。

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved