This function is to realize the closing of general HTML and UBB tags. I have seen it in pjblog before, but it has never been used. This function is good. It is recommended that you refer to the function in pjblog. Function closeUBB(strContent)
'************************************
'Automatically close UBB
'************************************
Dim arrTags, i, OpenPos, ClosePos, re, strMatchs, j, Match
Set re = New RegExp 'Declare the re object
re.IgnoreCase = True 'Set whether characters are case-sensitive
re.Global = True 'Set global availability
arrTags = Array(code, quote, list, color, align, font, size, b, i, u, html) 'Create an array and store related tags that need to be checked for closure
For i = 0 To UBound(arrTags) 'Loop to detect each element in the array
OpenPos = 0 'Initialize the number of start tags of the current label
ClosePos = 0 'Initialize the number of end tags of the current tag
re.Pattern = /[ + arrTags(i) + (=[^/[/]]+|)/] 'Start to judge the number of start and end tags respectively
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 'When the number of start and end tags is inconsistent, close the current tag
strContentstrContent = strContent + [/ + arrTags(i) + ]
Next
Next
closeUBB = strContent
Set re=Nothing
End Function
program code
Function closeHTML(strContent)
'************************************
'Automatically close 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
The following is the function code of pjblog, but there are no comments. It is recommended to refer to the above comments for study and research.
Copy the code code as follows:
'************************************
'Automatically close 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
'************************************
'Automatically close 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