欢迎光临
我们一直在努力

根据需要动态include不同的文件

建站超值云服务器,限时71元/月

受<! #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")

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 根据需要动态include不同的文件
分享到: 更多 (0)

相关推荐

  • 暂无文章