加入收藏 | 设为首页 | 会员中心 | 我要投稿 聊城站长网 (https://www.0635zz.com/)- 智能语音交互、行业智能、AI应用、云计算、5G!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

asp内简单说明的 HTML/ubb自动关闭标签功能

发布时间:2023-05-29 13:44:56 所属栏目:Asp教程 来源:
导读:这样的功能就是实现一般html,ubb标签的闭合,以前在pjblog中见过,一直没用,这个函数不错,建议可以参考下pjblog中的函数。

Function closeUBB(strContent)

'*************************************
这样的功能就是实现一般html,ubb标签的闭合,以前在pjblog中见过,一直没用,这个函数不错,建议可以参考下pjblog中的函数。
 
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
 
 

(编辑:聊城站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章