asp之自动闭合HTML/ubb标签函数 附简单注释
这最近在PJ的function库里看到的这个函数,感觉思路差了点,不过相对比较完美,只是闭合标签时的顺序问题,呵呵
修改一下数组arrTags里的各元素内容,可以达到闭合任何标签的功能。
在此,我给增加了一些注释,方便大家一起学习学习
closehtml的注释同上
修改一下数组arrTags里的各元素内容,可以达到闭合任何标签的功能。
在此,我给增加了一些注释,方便大家一起学习学习
代码如下:
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 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 Set re = Nothing End Function
closehtml的注释同上
代码如下:
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 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 Set re = Nothing End Function
相关推荐
lupeng 2020-11-14
sjcheck 2020-11-10
sjcheck 2020-11-03
meylovezn 2020-08-28
owhile 2020-08-18
Francismingren 2020-08-17
pythonclass 2020-07-29
sunzhihaofuture 2020-07-19
爱读书的旅行者 2020-07-07
行吟阁 2020-07-05
tianqi 2020-07-05
行吟阁 2020-07-04
冰蝶 2020-07-04
lyg0 2020-07-04
owhile 2020-07-04
opspider 2020-06-28
lengyu0 2020-06-28
tianqi 2020-06-21
dadaooxx 2020-06-16