熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

asp之自動閉合HTML/ubb標簽函數

2022-06-13   來源: .NET編程 

  Function closehtml(strContent)
*************************************
自動閉合html
*************************************
Dim arrTags i OpenPos ClosePos re strMatchs j Match
Set re = New RegExp
reIgnoreCase = True
reGlobal = True
arrTags = Array("p" "DIV" "span" "table" "ul" "font" "b" "u" "i" "h" "h" "h" "h" "h" "h")
For i = To UBound(arrTags)
OpenPos =
ClosePos =
rePattern = "<" + arrTags(i) + "( [^<>]+|)>"
Set strMatchs = reExecute(strContent)
For Each Match in strMatchs
OpenPos = OpenPos +
Next
rePattern = "</" + arrTags(i) + ">"
Set strMatchs = reExecute(strContent)
For Each Match in strMatchs
ClosePos = ClosePos +
Next
For j = To OpenPos ClosePos
strContent = strContent + "</" + arrTags(i) + ">"
Next
Next
closehtml = strContent
Set re = Nothing
End Function
Function closeUBB(strContent)
*************************************
自動閉合UBB
*************************************
Dim arrTags i OpenPos ClosePos re strMatchs j Match
Set re = New RegExp 申明re對象
reIgnoreCase = True 設置是否區分字符大小寫
reGlobal = True 設置全局可用性
arrTags = Array("code" "quote" "list" "color" "align" "font" "size" "b" "i" "u" "html")

  建立數組存儲相關需要檢測是否閉合的標簽
For i = To UBound(arrTags) 循環對數組裡的每一個元素進行檢測
OpenPos = 初始化當前標簽開始標記的個數
ClosePos = 初始化當前標簽結束標記的個數
rePattern = "[" + arrTags(i) + "(=[^[]]+|)]" 開始分別正則判斷開始與結束標記的個數
Set strMatchs = reExecute(strContent)
For Each Match in strMatchs
OpenPos = OpenPos +
Next
rePattern = "[/" + arrTags(i) + "]"
Set strMatchs = reExecute(strContent)
For Each Match in strMatchs
ClosePos = ClosePos +
Next
For j = To OpenPos ClosePos 當開始與結束標記數量不一致時閉合當前標簽
strContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
Set re = Nothing
End Function


From:http://tw.wingwit.com/Article/program/net/201311/14343.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.