当前位置: 移动技术网 > IT编程>开发语言>Asp > 如何在ASP页面动态Inclue文件?

如何在ASP页面动态Inclue文件?

2017年12月12日  | 移动技术网IT编程  | 我要评论
受<! #include file="filename.asp" --> 宏限制 
必须存在该文件并且会预先编译(不管前面是否加以条件) 

经常有这样的要求,根据不同的需求要求include不同的文件 
如各个人的不同设置,所以要求能动态include文件。 

代码如下: 

function include(filename) 
dim re,content,fso,f,aspstart,aspend
set fso=createobject("scripting.filesystemobject") 
set f=fso.opentextfile(server.mappath(filename)) 
content=f.readall 
f.close 
set f=nothing 
set fso=nothing 

set re=new regexp 
re.pattern="^\s*=" 
aspend=1 
aspstart=instr(aspend,content,"<%")+2 
do while aspstart>aspend+1 
response.write mid(content,aspend,aspstart-aspend-2) 
aspend=instr(aspstart,content,"%\>")+2 
execute(re.replace(mid(content,aspstart,aspend-aspstart-2),"response.write ")) 
aspstart=instr(aspend,content,"<%")+2 
loop 
response.write mid(content,aspend) 
set re=nothing 
end function 

使用范例: 

include("youinc.asp") 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网