主頁(yè) > 知識(shí)庫(kù) > asp之自動(dòng)閉合HTML/ubb標(biāo)簽函數(shù) 附簡(jiǎn)單注釋

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

熱門標(biāo)簽:團(tuán)購(gòu)網(wǎng)站 阿里云 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 銀行業(yè)務(wù) Mysql連接數(shù)設(shè)置 Linux服務(wù)器 服務(wù)器配置 電子圍欄
這最近在PJ的function庫(kù)里看到的這個(gè)函數(shù),感覺(jué)思路差了點(diǎn),不過(guò)相對(duì)比較完美,只是閉合標(biāo)簽時(shí)的順序問(wèn)題,呵呵
修改一下數(shù)組arrTags里的各元素內(nèi)容,可以達(dá)到閉合任何標(biāo)簽的功能。
在此,我給增加了一些注釋,方便大家一起學(xué)習(xí)學(xué)習(xí)
復(fù)制代碼 代碼如下:

Function closeUBB(strContent)
'*************************************
'自動(dòng)閉合UBB
'*************************************
Dim arrTags, i, OpenPos, ClosePos, re, strMatchs, j, Match
Set re = New RegExp '申明re對(duì)象
re.IgnoreCase = True '設(shè)置是否區(qū)分字符大小寫
re.Global = True '設(shè)置全局可用性
arrTags = Array("code", "quote", "list", "color", "align", "font", "size", "b", "i", "u", "html") '建立數(shù)組,存儲(chǔ)相關(guān)需要檢測(cè)是否閉合的標(biāo)簽
For i = 0 To UBound(arrTags) '循環(huán)對(duì)數(shù)組里的每一個(gè)元素進(jìn)行檢測(cè)
OpenPos = 0 '初始化當(dāng)前標(biāo)簽開始標(biāo)記的個(gè)數(shù)
ClosePos = 0 '初始化當(dāng)前標(biāo)簽結(jié)束標(biāo)記的個(gè)數(shù)
re.Pattern = "\[" + arrTags(i) + "(=[^\[\]]+|)\]" '開始分別正則判斷開始與結(jié)束標(biāo)記的個(gè)數(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ù)量不一致時(shí),閉合當(dāng)前標(biāo)簽
strContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
Set re = Nothing
End Function

closehtml的注釋同上
復(fù)制代碼 代碼如下:

Function closehtml(strContent)
'*************************************
'自動(dòng)閉合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實(shí)現(xiàn)HTML標(biāo)簽自動(dòng)補(bǔ)全代碼
  • asp自動(dòng)補(bǔ)全html標(biāo)簽自動(dòng)閉合(正則表達(dá)式)
  • js自動(dòng)閉合html標(biāo)簽(自動(dòng)補(bǔ)全html標(biāo)記)
  • asp之自動(dòng)閉合HTML/ubb標(biāo)簽函數(shù)附簡(jiǎn)單注釋
  • php使HTML標(biāo)簽自動(dòng)補(bǔ)全閉合函數(shù)代碼

標(biāo)簽:萍鄉(xiāng) 廣元 棗莊 大理 江蘇 蚌埠 衢州 衡水

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp之自動(dòng)閉合HTML/ubb標(biāo)簽函數(shù) 附簡(jiǎn)單注釋》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266