asp之自動(dòng)閉合HTML/ubb標(biāo)簽函數(shù)附簡(jiǎn)單注釋
'*************************************
'自動(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
OpenPosOpenPos = OpenPos + 1
Next
re.Pattern = "\[/" + arrTags(i) + "\]"
Set strMatchs = re.Execute(strContent)
For Each Match in strMatchs
ClosePosClosePos = ClosePos + 1
Next
For j = 1 To OpenPos - ClosePos '當(dāng)開始與結(jié)束標(biāo)記數(shù)量不一致時(shí),閉合當(dāng)前標(biāo)簽
strContentstrContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
Set re = Nothing
End Function
程序代碼
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
OpenPosOpenPos = OpenPos + 1
Next
re.Pattern = "\</" + arrTags(i) + "\>"
Set strMatchs = re.Execute(strContent)
For Each Match in strMatchs
ClosePosClosePos = ClosePos + 1
Next
For j = 1 To OpenPos - ClosePos
strContentstrContent = strContent + "</" + arrTags(i) + ">"
Next
Next
closeHTML = strContent
Set re = Nothing
End Function
下面的是pjblog的函數(shù)代碼,但沒(méi)有注釋,學(xué)習(xí)研究建議參考上面的注釋
'*************************************
'自動(dòng)閉合UBB
'*************************************
Function closeUBB(strContent)
Dim arrTags, i, OpenPos, ClosePos, re, strMatchs, j, Match
Set re = New RegExp
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
End Function
'*************************************
'自動(dòng)閉合HTML
'*************************************
Function closeHTML(strContent)
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
End Function
相關(guān)文章
asp文章中隨機(jī)插入網(wǎng)站版權(quán)文字的實(shí)現(xiàn)代碼
網(wǎng)站不斷被人抄襲采集,在百度對(duì)采集網(wǎng)站還沒(méi)有有效的打擊下,我們不能指望百度可以識(shí)別這些采集網(wǎng)站,那么只能依靠我們自己給我們辛辛苦苦做的內(nèi)容加上版權(quán)文字,以打擊這種不勞而獲的采集行為。2008-08-08ASP+FSO生成的網(wǎng)頁(yè)文件默認(rèn)編碼格式以及轉(zhuǎn)換成UTF-8編碼方法
有一個(gè)客人的網(wǎng)站想做一個(gè)俄文版,前臺(tái)后臺(tái),我統(tǒng)一用utf-8編碼,但通過(guò)數(shù)據(jù)庫(kù)生成的靜態(tài)俄文信息是亂碼。如果用GB2312顯示,通過(guò)數(shù)據(jù)庫(kù)生成的靜態(tài)俄文信息正確顯示, 但模板文件俄文是亂碼。2009-11-11asp cint clng的范圍與防止cint和clng的溢出解決方法大全
首先我們需要了解的是cint范圍 -32,768 到 32,767。 clng范圍 -2,147,483,648 到 2,147,483,647。2008-01-01.NET?Core?分布式任務(wù)調(diào)度ScheduleMaster詳解
這篇文章主要介紹了分布式任務(wù)調(diào)度ScheduleMaster,集中任務(wù)調(diào)度系統(tǒng),最簡(jiǎn)單的理解ScheduleMaster,就是對(duì)不同的系統(tǒng)里面的調(diào)度任務(wù)做統(tǒng)一管理的框架,本文通過(guò)圖文實(shí)例代碼相結(jié)合給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-05-05asp中判斷服務(wù)器是否安裝了某種組件的函數(shù)
檢查是否存在系統(tǒng)組件或組件是否安裝成功,方便繼續(xù)的操作。給用戶更好的信息指示。2010-12-12ASP操作Excel相關(guān)技術(shù)總結(jié)
ASP操作Excel相關(guān)技術(shù)總結(jié)...2007-05-05ASP中Server.Execute和Execute實(shí)現(xiàn)動(dòng)態(tài)包含(include)腳本的區(qū)別
ASP中Server.Execute和Execute實(shí)現(xiàn)動(dòng)態(tài)包含(include)腳本的區(qū)別,需要的朋友可以參考下。2012-01-01關(guān)于WPF?WriteableBitmap類直接操作像素點(diǎn)的問(wèn)題
WPF是微軟新一代圖形系統(tǒng),運(yùn)行在.NET Framework 3.0及以上版本下,為用戶界面、2D/3D 圖形、文檔和媒體提供了統(tǒng)一的描述和操作方法,本文重點(diǎn)給大家介紹WPF?WriteableBitmap類直接操作像素點(diǎn)的問(wèn)題,感興趣的朋友一起看看吧2022-01-01