Asp class一个标签引擎类tagEngine.Class_ASP教程

编辑Tag赚U币
教程Tag:暂无Tag,欢迎添加,赚取U币!

推荐:Asp+Ajax实现无刷新增加好友
由于工作关系,要做个人空间,其中有一功能是增加对方为好友.如图: 用到的方法是ajax,费话少说贴切代码: a href=javascript:void(0); onClick =add_username('%= rs(username) %');加为好友/a,用到的js验证: script language = JavaScript src=ajax.

一个用来实现tag功能的asp类,具体的作用,如果您可以读懂的话就可以明白了了。

修改记录:
1,增加扩展函数,2006-12-3

<%
'******************************
'类名:tagEngine
'名称:标签引擎
'日期:2006-11-29
'作者:西楼冷月
'网址:www.xilou.net | www.chinaCMS.org
'描述:只有提取标签功能,没有解析标签功能
'版权:转载请注名出处,作者
'******************************
'最后修改:2006-12-3
'修改次数:3
'修改说明:修改正则,使匹配更精确
'目前版本:v1.1.3
'******************************
Class tagEngine

Private regEx'正则对象

'定义标签规则
Private tagbegin
Private tagend
Private blockbegin_begin
Private blockbegin_end
Private blockend_begin
Private blockend_end
'//初始化
Private Sub Class_Initialize()
'初始化标签规则
tagbegin="{"
tagend="}"
blockbegin_begin="<Block:"
blockbegin_end =">"
blockend_begin ="</Block:"
blockend_end =">"
'初始化正则对象
Set regEx=new RegExp
regEx.IgnoreCase=True'不区分大小写
regEx.Global=True'全局匹配
End Sub
Private Sub Class_Terminate()
'释放对象
If IsObject(regEx) Then Set regEx=Nothing
End Sub

'方法:resetPattern()
'参数:
'返回:无返回值
'作用:重设标签规则
Public Sub resetPattern(tagbegin,tagend,_
blockbegin_begin,_
blockbegin_end,_
blockend_begin,_
blockend_end _
)
tagbegin=tagbegin
tagend=tagend
blockbegin_begin=blockbegin_begin
blockbegin_end =blockbegin_end
blockend_begin =blockend_begin
blockend_end =blockend_end
End Sub

'方法:getBlocks(temp,blockname)
'参数:temp,要匹配的内容;blockname,区块标志名称
'返回:返回集合对象(Matches)
'作用:获取块标签集合
Public Function getBlocks(temp,blockname)
Dim pattern
pattern="("&blockbegin_begin&"[ ]*"&blockname&"\b[\w\W]*?"&blockbegin_end
pattern=pattern&")([\w\W]*?)"&blockend_begin&"[ \n\r]*"&blockname&"[ ]*"&blockend_end
'Response.Write pattern
regEx.Pattern=pattern
Set getBlocks=regEx.Execute(temp)'返回匹配集合
End Function

'方法:getBlockByAtt(temp,attributename,attributevalue)
'参数:temp,要匹配的内容;attributename,属性名称;attributevalue,属性值
'返回:返回集合对象(Matches)
'作用:根据块标签里的某个属性的值取得符合的块集合
Public Function getBlockByAtt(temp,attributename,attributevalue)
Dim pattern
pattern="("&blockbegin_begin&"[\w\W]*?[ \n\r]+"&attributename
pattern=pattern&"[ ]*=[ ]*\"&Chr(34)&attributevalue&"\"&Chr(34)&"[ \n\r]*[\w\W]*?"
pattern=pattern&blockbegin_end
pattern=pattern&")([\w\W]*?)"&blockend_begin&"[\w\W]*?"&blockend_end
'Response.Write pattern
regEx.Pattern=pattern
Set getBlockByAtt=regEx.Execute(temp)'返回匹配集合
End Function

'方法:getAttValue(temp,attributename)
'参数:temp,要匹配的内容;attributename,属性名称
'返回:返回集合对象(Matches)
'作用:获取块标签内的属性值
Public Function getAttValue(temp,attributename)
Dim pattern
pattern="[ \n\r]+"&attributename&"[ ]*=[ ]*\"&Chr(34)&"([^\f\n\r\t\v\"&Chr(34)&"]*?)\"&Chr(34)
'Response.Write pattern
regEx.Pattern=pattern
Set getAttValue=regEx.Execute(temp)
End Function

'方法:parseTag(temp,tagname,tagvalue)
'参数:temp,要匹配的内容;attributename,属性名称;attributevalue,属性值
'返回:返回替换后的字符串
'作用:替换简单标签
Public Function parseTag(temp,tagname,tagvalue)
Dim pattern
'pattern=tagbegin&"[ ]*"&tagname&"[ ]*"&tagend
pattern=tagbegin&tagname&tagend
regEx.pattern=pattern
parseTag=regEx.Replace(temp,tagvalue)
End Function

'方法:clearBlocks(temp)
'参数:temp,要匹配的内容
'返回:返回清除后的字符串
'作用:清除所有块标签
Public Function clearBlocks(temp)
Dim pattern
pattern=blockbegin_begin&"[\w\W]*?"&blockbegin_end&"[\w\W]*?"
pattern=pattern&blockend_begin&"[\w\W]*?"&blockend_end
regEx.pattern=pattern
clearBlocks=regEx.Replace(temp,"")
End Function

'方法:clearTags(temp)
'参数:temp,要匹配的内容
'返回:返回清除后的字符串
'作用:清除所有的单标签
Public Function clearTags(temp)
Dim pattern
pattern=tagbegin&"[^\f\n\r\t\v]*?"&tagend
regEx.pattern=pattern
clearTags=regEx.Replace(temp,"")
End Function

'方法:showError(errdes)
'参数:errdes,错误描述
'返回:无
'作用:显示错误
Public Sub showError(errdes)
Dim errinfo,cssstyle
cssstyle="style="&Chr(34)
cssstyle=cssstyle&"font:bold 12px 150%,'Arial';border:1px solid #CC3366;"
cssstyle=cssstyle&"width:50%;color:#990066;padding:2px;"&Chr(34)
errinfo=vbcrlf&"<ul "&cssstyle&"><li>"&errdes&"</li></ul>"&vbcrlf
Response.Write errinfo
End Sub

'******************标准功能结束****************
'以下是自定义扩展功能

'方法:EXT_getSimpleBlocks(temp,blockname)
'参数:temp,要匹配的内容;blockname,区块标志名称
'返回:返回集合对象(Matches)
'作用:获取简单块标签集合
'例子:<Block:new id="" loop=""/>
Public Function EXT_getSimpleBlocks(temp,blockname)
Dim pattern
Dim blockbegin,blockend
'重新定义标签规则
blockbegin="<Block:"
blockend ="/>"
pattern=blockbegin&"[ ]*"&blockname&"\b[\w\W]*?"&blockend
regEx.pattern=pattern
Set EXT_getSimpleBlocks=regEx.Execute(temp)
End Function

'******************标准功能结束****************
'以下是自定义扩展功能

'方法:EXT_getSimpleBlocks(temp,blockname)
'参数:temp,要匹配的内容;blockname,区块标志名称
'返回:返回集合对象(Matches)
'作用:获取简单块标签集合
'例子:<Block:new id="" loop=""/>
Public Function EXT_getSimpleBlocks(temp,blockname)
Dim pattern
Dim blockbegin,blockend
'重新定义标签规则
blockbegin="<Block:"
blockend ="/>"
pattern=blockbegin&"[ ]*"&blockname&"\b[\w\W]*?"&blockend
regEx.pattern=pattern
Set EXT_getSimpleBlocks=regEx.Execute(temp)
End Function

'方法:EXT_getTEXT(path)
'参数:path,要读取的文本相对或绝对路径
'返回:返回文本内容
'作用: 读取文件
'例子:c=EXT_getTEXT("tpl.htm")
Public Function EXT_getTEXT(path)
Dim fso,f,text
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
Set f=Fso.OpenTextFile(path)
text=f.ReadAll
If Err Then
Err.Clear
showError "读取文件出错..."
If IsObject(fso) Then Set fso=Nothing
Exit Function
End If
If IsObject(fso) Then Set fso=Nothing
EXT_getTEXT=text
End Function

'方法:EXT_getIncludeFile(temp)
'参数:temp,要匹配的内容
'返回:返回集合对象(Matches)
'作用: 解析<!--#include file="tpl.html"-->的区块
'例子:EXT_getIncludeFile(temp)(0).SubMatches(0),返回第一个匹配的文件名
Public Function EXT_getIncludeFile(temp)
Dim pattern
Dim blockbegin,blockend
'重新定义标签规则
blockbegin="<!--#include"
blockend ="-->"
pattern=blockbegin&"[ ]*file[ ]*=[ ]*\""([\w\W]*?)\""[ ]*"&blockend
regEx.pattern=pattern
Set EXT_getIncludeFile=regEx.Execute(temp)
End Function

End Class
%>

分享:ASP限制ip投票完整实例代码
由于工作关系,要做个人空间,其中有一功能是对用户投票,要求同一IP只能对同一用户投票一次,贴Asp代码: % '作者:无情 出处: db_conn(dbs) Voteusername=trim(request.QueryString(username)) rs_create(select username from [user] where username ='

来源:模板无忧//所属分类:ASP教程/更新时间:2012-06-10
相关ASP教程