当前位置:首页 > ASP教程 > ASP基础

ASP动态include文件

 经常有这样的要求,根据不同的需求要求include不同的文件如各个人的不同设置,所以要求能动态include文件受<! #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")



【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!

相关教程推荐

其他课程推荐