學(xué)asp的應(yīng)該知道,自動(dòng)閉合html/ubb變遷函數(shù)有些煩人的,我現(xiàn)在雖然是做電話錄音卡銷售工作的,雖然那么長(zhǎng)時(shí)間沒(méi)看書(shū)了,不過(guò)我嘛上學(xué)時(shí)對(duì)程序都有些敏感,所以寫(xiě)下這個(gè)程序共大家參考一下:
FunctioncloseUBB(strContent)
'*************************************
'自動(dòng)閉合UBB
'*************************************
DimarrTags,i,OpenPos,ClosePos,re,strMatchs,j,Match
Setre=NewRegExp'申明re對(duì)象
re.IgnoreCase=True'設(shè)置是否區(qū)分字符大小寫(xiě)
re.Global=True'設(shè)置全局可用性
arrTags=Array("code","quote","list","color","align","font","size","b","i","u","html")'建立數(shù)組,存儲(chǔ)相關(guān)需要檢測(cè)是否閉合的標(biāo)簽
Fori=0ToUBound(arrTags)'循環(huán)對(duì)數(shù)組里的每一個(gè)元素進(jìn)行檢測(cè)
OpenPos=0'初始化當(dāng)前標(biāo)簽開(kāi)始標(biāo)記的個(gè)數(shù)
ClosePos=0'初始化當(dāng)前標(biāo)簽結(jié)束標(biāo)記的個(gè)數(shù)
re.Pattern="\["+arrTags(i)+"(=[^\[\]]+|)\]"'開(kāi)始分別正則判斷開(kāi)始與結(jié)束標(biāo)記的個(gè)數(shù)
SetstrMatchs=re.Execute(strContent)
ForEachMatchinstrMatchs
OpenPosOpenPos=OpenPos+1
Next
re.Pattern="\[/"+arrTags(i)+"\]"
SetstrMatchs=re.Execute(strContent)
ForEachMatchinstrMatchs
ClosePosClosePos=ClosePos+1
Next
Forj=1ToOpenPos-ClosePos'當(dāng)開(kāi)始與結(jié)束標(biāo)記數(shù)量不一致時(shí),閉合當(dāng)前標(biāo)簽
strContentstrContent=strContent+"[/"+arrTags(i)+"]"
Next
Next
closeUBB=strContent
Setre=Nothing
EndFunction
程序代碼程序代碼
FunctioncloseHTML(strContent)
'*************************************
'自動(dòng)閉合HTML
'*************************************
DimarrTags,i,OpenPos,ClosePos,re,strMatchs,j,Match
Setre=NewRegExp
re.IgnoreCase=True
re.Global=True
arrTags=Array("p","div","span","table","ul","font","b","u","i","h1","h2","h3","h4","h5","h6")
Fori=0ToUBound(arrTags)
OpenPos=0
ClosePos=0
re.Pattern="\<"+arrTags(i)+"([^\<\>]+|)\>"
SetstrMatchs=re.Execute(strContent)
ForEachMatchinstrMatchs
OpenPosOpenPos=OpenPos+1
Next
re.Pattern="\</"+arrTags(i)+"\>"
SetstrMatchs=re.Execute(strContent)
ForEachMatchinstrMatchs
ClosePosClosePos=ClosePos+1
Next
Forj=1ToOpenPos-ClosePos
strContentstrContent=strContent+"</"+arrTags(i)+">"
Next
Next
closeHTML=strContent
Setre=Nothing
EndFunction
其實(shí)語(yǔ)言這東西學(xué)習(xí)就像兒時(shí)學(xué)習(xí)語(yǔ)言一樣,要對(duì)他充滿好奇,這樣才不會(huì)感覺(jué)枯燥無(wú)味!
如對(duì)本文有疑問(wèn),請(qǐng)?zhí)峤坏浇涣髡搲?,廣大熱心網(wǎng)友會(huì)為你解答??! 點(diǎn)擊進(jìn)入論壇