asp之自动闭合HTML/ubb标签函数附简单注释

来源:asp之家 时间:2011-04-04 11:18:00 

Function closeUBB(strContent) 
'************************************* 
'自动闭合UBB 
'************************************* 
Dim arrTags, i, OpenPos, ClosePos, re, strMatchs, j, Match 
Set re = New RegExp '申明re对象 
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 
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 
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的函数代码,但没有注释,学习研究建议参考上面的注释

代码如下:


'************************************* 
'自动闭合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

标签:asp,自动闭合,HTML,ubb
0
投稿

猜你喜欢

  • Oracle 9i 数据库异常关闭后的启动

    2010-07-20 12:49:00
  • jRaiser与jQuery的冲突问题

    2010-07-27 12:36:00
  • 09七夕节各大搜索引擎LOGO欣赏

    2009-08-27 15:34:00
  • asp如何取回已忘记的密码?

    2010-05-13 16:33:00
  • 用SQL语句生成带有小计合计的数据集脚本

    2009-01-06 11:33:00
  • asp和js两种方法判断远程图片是否存在

    2007-09-21 17:27:00
  • Oracle数据库编写有效事务指导方针

    2009-03-19 17:41:00
  • SQL Server数据库对于应用程序的关系

    2010-09-08 09:42:00
  • sqlserver 导出插入脚本代码

    2012-01-29 18:04:43
  • 正则 global 属性介绍

    2008-03-18 20:50:00
  • 如何用SQLMail建立一个电子刊物自动处理系统?

    2010-06-13 14:36:00
  • 在ASP应用程序中加入智能搜索

    2007-09-18 13:15:00
  • ASP防盗链及防下载的方法

    2007-09-19 12:22:00
  • SQL Server 2000 占内存居高不下可能的原因及其解决方法

    2010-04-25 10:39:00
  • 一个修改Oracle数据库用户密码的小诀窍

    2009-09-30 15:29:00
  • 如何使用表格来储存数据库的记录?

    2010-05-16 15:14:00
  • 教你快速掌握数据库查询优化的实用技巧

    2008-11-28 15:10:00
  • ASP编程入门进阶教程

    2008-06-29 18:00:00
  • JS判断是否为数字、JS判断是否为整数、JS判断是否为浮点数

    2008-11-19 16:42:00
  • 三种SQL分页法

    2010-05-07 11:03:00
  • asp之家 网络编程 m.aspxhome.com