国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > ASP > 正文

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

2020-07-27 12:51:29
字體:
來源:轉載
供稿:網友
這最近在PJ的function庫里看到的這個函數,感覺思路差了點,不過相對比較完美,只是閉合標簽時的順序問題,呵呵
修改一下數組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
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 辽宁省| 仁寿县| 陆丰市| 高阳县| 凤山市| 岑巩县| 克山县| 阳信县| 伊吾县| 彰武县| 安溪县| 陆河县| 嵊泗县| 含山县| 克什克腾旗| 温州市| 鄱阳县| 银川市| 大理市| 东源县| 康定县| 灵寿县| 宜兴市| 和平县| 黄陵县| 镇赉县| 洞头县| 句容市| 龙口市| 逊克县| 建德市| 玛纳斯县| 孟连| 古浪县| 灯塔市| 福鼎市| 烟台市| 张家港市| 宣威市| 酒泉市| 盘锦市|