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

(编辑:jimmy 日期: 2024/9/22 浏览:2)

受<! #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") 
一句话新闻
Windows上运行安卓你用过了吗
在去年的5月23日,借助Intel Bridge Technology以及Intel Celadon两项技术的驱动,Intel为PC用户带来了Android On Windows(AOW)平台,并携手国内软件公司腾讯共同推出了腾讯应用宝电脑版,将Windows与安卓两大生态进行了融合,PC的使用体验随即被带入到了一个全新的阶段。