asp

位置:IT落伍者 >> asp >> 浏览文章

asp之自动闭合HTML/ubb标签函数


发布日期:2019年08月20日
 
asp之自动闭合HTML/ubb标签函数

Function closehtml(strContent)
*************************************
自动闭合html
*************************************
Dim arrTags i OpenPos ClosePos re strMatchs j Match
Set re = New RegExp
reIgnoreCase = True
reGlobal = True
arrTags = Array("p" "DIV" "span" "table" "ul" "font" "b" "u" "i" "h" "h" "h" "h" "h" "h")
For i = To UBound(arrTags)
OpenPos =
ClosePos =
rePattern = "<" + arrTags(i) + "( [^<>]+|)>"
Set strMatchs = reExecute(strContent)
For Each Match in strMatchs
OpenPos = OpenPos +
Next
rePattern = "</" + arrTags(i) + ">"
Set strMatchs = reExecute(strContent)
For Each Match in strMatchs
ClosePos = ClosePos +
Next
For j = To OpenPos ClosePos
strContent = strContent + "</" + arrTags(i) + ">"
Next
Next
closehtml = strContent
Set re = Nothing
End Function
Function closeUBB(strContent)
*************************************
自动闭合UBB
*************************************
Dim arrTags i OpenPos ClosePos re strMatchs j Match
Set re = New RegExp 申明re对象
reIgnoreCase = True 设置是否区分字符大小写
reGlobal = True 设置全局可用性
arrTags = Array("code" "quote" "list" "color" "align" "font" "size" "b" "i" "u" "html")

建立数组存储相关需要检测是否闭合的标签
For i = To UBound(arrTags) 循环对数组里的每一个元素进行检测
OpenPos = 初始化当前标签开始标记的个数
ClosePos = 初始化当前标签结束标记的个数
rePattern = "[" + arrTags(i) + "(=[^[]]+|)]" 开始分别正则判断开始与结束标记的个数
Set strMatchs = reExecute(strContent)
For Each Match in strMatchs
OpenPos = OpenPos +
Next
rePattern = "[/" + arrTags(i) + "]"
Set strMatchs = reExecute(strContent)
For Each Match in strMatchs
ClosePos = ClosePos +
Next
For j = To OpenPos ClosePos 当开始与结束标记数量不一致时闭合当前标签
strContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
Set re = Nothing
End Function

               

上一篇:asp 实现远程登陆代码

下一篇:asp ubb代码转换成html代码