程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> ASP編程 >> 關於ASP編程 >> asp之自動閉合HTML/ubb標簽函數附簡單注釋

asp之自動閉合HTML/ubb標簽函數附簡單注釋

編輯:關於ASP編程
Function closeUBB(strContent)
'*************************************
'自動閉合UBB
'*************************************
Dim arrTags, i, OpenPos, ClosePos, re, strMatchs, j, Match
Set re = New RegExp '申明re對象
re.IgnoreCase = True '設置是否區分字符大小寫
re.Global = True '設置全局可用性
arrTags = Array("code", "quote", "list", "color", "align", "font", "size", "b", "i", "u", "html") '建立數組,存儲相關需要檢測是否閉合的標簽
For i = 0 To UBound(arrTags) '循環對數組裡的每一個元素進行檢測
OpenPos = 0 '初始化當前標簽開始標記的個數
ClosePos = 0 '初始化當前標簽結束標記的個數
re.Pattern = "\[" + arrTags(i) + "(=[^\[\]]+|)\]" '開始分別正則判斷開始與結束標記的個數
Set strMatchs = re.Execute(strContent)
For Each Match in strMatchs
OpenPosOpenPos = OpenPos + 1
Next
re.Pattern = "\[/" + arrTags(i) + "\]"
Set strMatchs = re.Execute(strContent)
For Each Match in strMatchs
ClosePosClosePos = ClosePos + 1
Next
For j = 1 To OpenPos - ClosePos '當開始與結束標記數量不一致時,閉合當前標簽
strContentstrContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
Set re = Nothing
End Function

程序代碼
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", "h5", "h6")
For i = 0 To UBound(arrTags)
OpenPos = 0
ClosePos = 0
re.Pattern = "\<" + arrTags(i) + "( [^\<\>]+|)\>"
Set strMatchs = re.Execute(strContent)
For Each Match in strMatchs
OpenPosOpenPos = OpenPos + 1
Next
re.Pattern = "\</" + arrTags(i) + "\>"
Set strMatchs = re.Execute(strContent)
For Each Match in strMatchs
ClosePosClosePos = ClosePos + 1
Next
For j = 1 To OpenPos - ClosePos
strContentstrContent = strContent + "</" + arrTags(i) + ">"
Next
Next
closeHTML = strContent
Set re = Nothing
End Function
下面的是pjblog的函數代碼,但沒有注釋,學習研究建議參考上面的注釋
復制代碼 代碼如下:
'*************************************
'自動閉合UBB
'*************************************

Function closeUBB(strContent)
Dim arrTags, i, OpenPos, ClosePos, re, strMatchs, j, Match
Set re = New RegExp
re.IgnoreCase = True
re.Global = True
arrTags = Array("code", "quote", "list", "color", "align", "font", "size", "b", "i", "u", "html")
For i = 0 To UBound(arrTags)
OpenPos = 0
ClosePos = 0

re.Pattern = "\[" + arrTags(i) + "(=[^\[\]]+|)\]"
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
strContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
End Function

'*************************************
'自動閉合HTML
'*************************************

Function closeHTML(strContent)
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", "h5", "h6")
For i = 0 To UBound(arrTags)
OpenPos = 0
ClosePos = 0

re.Pattern = "\<" + arrTags(i) + "( [^\<\>]+|)\>"
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
strContent = strContent + "</" + arrTags(i) + ">"
Next
Next
closeHTML = strContent
End Function
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved