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

首頁 > 編程 > ASP > 正文

asp之自動閉合HTML/ubb標(biāo)簽函數(shù) 附簡單注釋

2024-05-04 11:00:04
字體:
供稿:網(wǎng)友
這最近在PJ的function庫里看到的這個函數(shù),感覺思路差了點,不過相對比較完美,只是閉合標(biāo)簽時的順序問題,呵呵
修改一下數(shù)組arrTags里的各元素內(nèi)容,可以達(dá)到閉合任何標(biāo)簽的功能。
在此,我給增加了一些注釋,方便大家一起學(xué)習(xí)學(xué)習(xí)
復(fù)制代碼 代碼如下:
Function closeUBB(strContent)
'*************************************
'自動閉合UBB
'*************************************
Dim arrTags, i, OpenPos, ClosePos, re, strMatchs, j, Match
Set re = New RegExp '申明re對象
re.IgnoreCase = True '設(shè)置是否區(qū)分字符大小寫
re.Global = True '設(shè)置全局可用性
arrTags = Array("code", "quote", "list", "color", "align", "font", "size", "b", "i", "u", "html") '建立數(shù)組,存儲相關(guān)需要檢測是否閉合的標(biāo)簽
For i = 0 To UBound(arrTags) '循環(huán)對數(shù)組里的每一個元素進(jìn)行檢測
OpenPos = 0 '初始化當(dāng)前標(biāo)簽開始標(biāo)記的個數(shù)
ClosePos = 0 '初始化當(dāng)前標(biāo)簽結(jié)束標(biāo)記的個數(shù)
re.Pattern = "/[" + arrTags(i) + "(=[^/[/]]+|)/]" '開始分別正則判斷開始與結(jié)束標(biāo)記的個數(shù)
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 '當(dāng)開始與結(jié)束標(biāo)記數(shù)量不一致時,閉合當(dāng)前標(biāo)簽
strContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
Set re = Nothing
End Function

closehtml的注釋同上
復(fù)制代碼 代碼如下:
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

您可能感興趣的文章:

PHP實現(xiàn)HTML標(biāo)簽自動補全代碼asp自動補全html標(biāo)簽自動閉合(正則表達(dá)式)js自動閉合html標(biāo)簽(自動補全html標(biāo)記)asp之自動閉合HTML/ubb標(biāo)簽函數(shù)附簡單注釋php使HTML標(biāo)簽自動補全閉合函數(shù)代碼
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 新绛县| 中江县| 文水县| 天峻县| 定襄县| 柞水县| 扎兰屯市| 织金县| 英超| 文成县| 曲阜市| 包头市| 连城县| 丹江口市| 永胜县| 顺昌县| 磐石市| 兴和县| 平湖市| 宝鸡市| 驻马店市| 庆安县| 澎湖县| 宁海县| 云霄县| 宝丰县| 安庆市| 洛川县| 定州市| 新晃| 宜良县| 新泰市| 西乌| 涡阳县| 吉林市| 盐边县| 荃湾区| 呼玛县| 二连浩特市| 无锡市| 西青区|