asp之自動閉合HTML/ubb標(biāo)簽函數(shù)附簡單注釋
'*************************************
'自動閉合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ù)組里的每一個元素進行檢測
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
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ù)量不一致時,閉合當(dāng)前標(biāo)簽
strContentstrContent = strContent + "[/" + arrTags(i) + "]"
Next
Next
closeUBB = strContent
Set re = Nothing
End Function
程序代碼
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
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ù)代碼,但沒有注釋,學(xué)習(xí)研究建議參考上面的注釋
'*************************************
'自動閉合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
'*************************************
'自動閉合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文章中隨機插入網(wǎng)站版權(quán)文字的實現(xiàn)代碼
網(wǎng)站不斷被人抄襲采集,在百度對采集網(wǎng)站還沒有有效的打擊下,我們不能指望百度可以識別這些采集網(wǎng)站,那么只能依靠我們自己給我們辛辛苦苦做的內(nèi)容加上版權(quán)文字,以打擊這種不勞而獲的采集行為。2008-08-08ASP+FSO生成的網(wǎng)頁文件默認編碼格式以及轉(zhuǎn)換成UTF-8編碼方法
有一個客人的網(wǎng)站想做一個俄文版,前臺后臺,我統(tǒng)一用utf-8編碼,但通過數(shù)據(jù)庫生成的靜態(tài)俄文信息是亂碼。如果用GB2312顯示,通過數(shù)據(jù)庫生成的靜態(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),最簡單的理解ScheduleMaster,就是對不同的系統(tǒng)里面的調(diào)度任務(wù)做統(tǒng)一管理的框架,本文通過圖文實例代碼相結(jié)合給大家介紹的非常詳細,需要的朋友可以參考下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實現(xiàn)動態(tài)包含(include)腳本的區(qū)別
ASP中Server.Execute和Execute實現(xiàn)動態(tài)包含(include)腳本的區(qū)別,需要的朋友可以參考下。2012-01-01關(guān)于WPF?WriteableBitmap類直接操作像素點的問題
WPF是微軟新一代圖形系統(tǒng),運行在.NET Framework 3.0及以上版本下,為用戶界面、2D/3D 圖形、文檔和媒體提供了統(tǒng)一的描述和操作方法,本文重點給大家介紹WPF?WriteableBitmap類直接操作像素點的問題,感興趣的朋友一起看看吧2022-01-01