Function closehtml(strContent)
*************************************
自動閉合html
*************************************
Dim arrTags, i, OpenPos, ClosePos, re, strMatchs, j, Match
Set re = New RegExp
re.IgnoreCase = True
re.Global = True
arrTags = Array("p", "DIV", "span", "table", "ul", "font", "b", "u", "i", "h1", "h2", "h3", "h4", &quo
建立數(shù)組,存儲相關需要檢測是否閉合的標簽
For i = 0 To UBound(arrTags) '循環(huán)對數(shù)組里的每一個元素進行檢測
OpenPos = 0 '初始化當前標簽開始標記的個數(shù)
ClosePos = 0 '初始化當前標簽結束標記的個數(shù)
re.Pattern = "[" + arrTags(i) + "(=[^[]]+|)]" '開始分別正則判斷開始與結束標記的個數(shù)
Set strMatchs = re.Execute(strContent)
For Each Match in strMatchs
OpenPos = OpenPos + 1
Next
re.Pattern = "[/" + arrTags(i) + "]"
Set strMatchs = re.Execute(strContent)
For Each Match in strMatchs
ClosePos = ClosePos + 1
Next
For j = 1 To OpenPos - ClosePos '當開始與結束標記數(shù)量不一致時,閉合當前標簽
strContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
Set re = Nothing
End Function
新聞熱點
疑難解答