时间:2021-05-25
早在03年就在蓝色理想上看到过动态Include的文章,当时已经觉得很厉害,但实际应用了一下,不方便而且Include的效果不好.
后来又在一网站上看到了改进版的,但是也不太好用~~~
哎,当时我真是觉得有点想放弃ASP了,但是由于公司还是用ASP来开发,我也是没有办法...
今天,我一定要记住今天~~~在国外的一个网站上我竟然发现了这样一个好东东,太棒了~~~Greatworks!!!
以前试的一些动态Include代码,都无法Include一个类,甚至函数~~~又或者Include文件中的Include无法被包含...
现在这个鬼佬(dselkirk)写的类可以为我们做到这些了~~~
复制代码 代码如下:
<%
publicinclude,include_vars
setinclude=newcls_include
classcls_include
privatesubclass_initialize()
setinclude_vars=server.createobject("scripting.dictionary")
endsub
privatesubclass_deactivate()
arr_variables.removeall
setinclude_vars=nothing
setinclude=nothing
endsub
publicdefaultfunctioninclude(byvalstr_path)
dimstr_source
ifstr_path<>""then
str_source=readfile(str_path)
ifstr_source<>""then
processincludesstr_source
convert2codestr_source
formatcodestr_source
ifstr_source<>""then
ifrequest.querystring("debug")=1then
response.writestr_source
response.end
else
executeglobalstr_source
include_vars.removeall
endif
endif
endif
endif
endfunction
privatesubconvert2code(str_source)
dimi,str_temp,arr_temp,int_len
ifstr_source<>""then
ifinstr(str_source,"%"&">")>instr(str_source,"<"&"%")then
str_temp=replace(str_source,"<"&"%","|%")
str_temp=replace(str_temp,"%"&">","|")
ifleft(str_temp,1)="|"thenstr_temp=right(str_temp,len(str_temp)-1)
ifright(str_temp,1)="|"thenstr_temp=left(str_temp,len(str_temp)-1)
arr_temp=split(str_temp,"|")
int_len=ubound(arr_temp)
if(int_len+1)>0then
fori=0toint_len
str_temp=trim(arr_temp(i))
str_temp=replace(str_temp,vbcrlf&vbcrlf,vbcrlf)
ifleft(str_temp,2)=vbcrlfthenstr_temp=right(str_temp,len(str_temp)-2)
ifright(str_temp,2)=vbcrlfthenstr_temp=left(str_temp,len(str_temp)-2)
ifleft(str_temp,1)="%"then
str_temp=right(str_temp,len(str_temp)-1)
ifleft(str_temp,1)="="then
str_temp=right(str_temp,len(str_temp)-1)
str_temp="response.write"&str_temp
endif
else
ifstr_temp<>""then
include_vars.addi,str_temp
str_temp="response.writeinclude_vars.item("&i&")"
endif
endif
str_temp=replace(str_temp,chr(34)&chr(34)&"&","")
str_temp=replace(str_temp,"&"&chr(34)&chr(34),"")
ifright(str_temp,2)<>vbcrlfthenstr_temp=str_temp
arr_temp(i)=str_temp
next
str_source=join(arr_temp,vbcrlf)
endif
else
ifstr_source<>""then
include_vars.add"var",str_source
str_source="response.writeinclude_vars.item(""var"")"
endif
endif
endif
endsub
privatesubprocessincludes(str_source)
dimint_start,str_path,str_mid,str_temp
str_source=replace(str_source,"<!--#","<!--#")
int_start=instr(str_source,"<!--#include")
str_mid=lcase(getbetween(str_source,"<!--#include","-->"))
dountilint_start=0
str_mid=lcase(getbetween(str_source,"<!--","-->"))
int_start=instr(str_mid,"#include")
ifint_start>0then
str_temp=lcase(getbetween(str_mid,chr(34),chr(34)))
str_temp=trim(str_temp)
str_path=readfile(str_temp)
str_source=replace(str_source,"<!--"&str_mid&"-->",str_path&vbcrlf)
endif
int_start=instr(str_source,"#include")
loop
endsub
privatesubformatcode(str_code)
dimi,arr_temp,int_len
str_code=replace(str_code,vbcrlf&vbcrlf,vbcrlf)
ifleft(str_code,2)=vbcrlfthenstr_code=right(str_code,len(str_code)-2)
str_code=trim(str_code)
ifinstr(str_code,vbcrlf)>0then
arr_temp=split(str_code,vbcrlf)
fori=0toubound(arr_temp)
arr_temp(i)=ltrim(arr_temp(i))
ifarr_temp(i)<>""thenarr_temp(i)=arr_temp(i)&vbcrlf
next
str_code=join(arr_temp,"")
arr_temp=vbnull
endif
endsub
privatefunctionreadfile(str_path)
dimobjfso,objfile
ifstr_path<>""then
ifinstr(str_path,":")=0thenstr_path=server.mappath(str_path)
setobjfso=server.createobject("scripting.filesystemobject")
ifobjfso.fileexists(str_path)then
setobjfile=objfso.opentextfile(str_path,1,false)
iferr.number=0then
readfile=objfile.readall
objfile.close
endif
setobjfile=nothing
endif
setobjfso=nothing
endif
endfunction
privatefunctiongetbetween(strdata,strstart,strend)
dimlngstart,lngend
lngstart=instr(strdata,strstart)+len(strstart)
if(lngstart<>0)then
lngend=instr(lngstart,strdata,strend)
if(lngend<>0)then
getbetween=mid(strdata,lngstart,lngend-lngstart)
endif
endif
endfunction
endclass
%>
声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。
本文实例讲述了JQuery动态添加和删除表格行的方法。分享给大家供大家参考。具体分析如下:昨天做页面表格行动态添加和删除,看了无数的介绍,发现了一个好东东,JQ
使用jquery动态加载js,css文件复制代码代码如下:$.extend({includePath:'',include:function(file){var
本文实例讲述了ActiveMQ在C#中的应用。分享给大家供大家参考,具体如下:ActiveMQ是个好东东,不必多说。ActiveMQ提供多种语言支持,如Java
C++读写文件安全又简洁的简单实例实例代码:#include#include#includeusingnamespacestd;intget_file_cont
本文实例讲述了php多次include后导致全局变量global失效的解决方法。分享给大家供大家参考。具体分析如下:在多个文件中,文件一个接一个include,