您的位置广东网盟 > 文章资讯 > 软件应用 > 编程开发 > ASP技术 > 文章内容

asp动态include文件

作者:佚名  来源:本站整理  发布时间:2008-4-30 15:47:27

受<! #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
%>

Tags:广东网盟  
  •         用户名: 验证码: 验证码,看不清楚请点击刷新验证码 (注“”为必填内容。)


    文章评论: [ 查看全部 ] 网友评论
    关于网盟 | 网站帮助 | 广告合作 | 下载声明 | 友情连接 | 联系方式

    Copyright © 2003-2008 Gdwg.Net. All Rights Reserved .
    中国广东网管联盟设计维护.网站备案:粤ICP备08020875号