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

首頁(yè) > 編程 > ASP > 正文

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

2024-05-04 11:09:01
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友
這樣的功能就是實(shí)現(xiàn)一般html,ubb標(biāo)簽的閉合,以前在pjblog中見(jiàn)過(guò),一直沒(méi)用,這個(gè)函數(shù)不錯(cuò),建議可以參考下pjblog中的函數(shù)。
 
 
 
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ū)分字符大小寫(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)簽 
For i = 0 To UBound(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ù) 
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)開(kāi)始與結(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)有注釋?zhuān)瑢W(xué)習(xí)研究建議參考上面的注釋
復(fù)制代碼代碼如下:

'************************************* 
'自動(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

發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 牡丹江市| 通海县| 益阳市| 凭祥市| 德阳市| 台前县| 黄石市| 修武县| 漠河县| 南通市| 太仓市| 施甸县| 临安市| 维西| 平邑县| 横山县| 亳州市| 青川县| 大连市| 红安县| 玛沁县| 泰宁县| 天峨县| 萨迦县| 晋江市| 灵寿县| 宜川县| 白朗县| 蕲春县| 高雄市| 垫江县| 乌拉特后旗| 三明市| 年辖:市辖区| 南昌县| 达尔| 绍兴市| 昭平县| 新干县| 闽清县| 山东|