加入收藏 | 设为首页 | 会员中心 | 我要投稿 银川站长网 (https://www.0951zz.com/)- 云通信、基础存储、云上网络、机器学习、视觉智能!
当前位置: 首页 > 站长学院 > Asp教程 > 正文

如何于ASP页面动态Inclue文件

发布时间:2023-08-23 13:02:26 所属栏目:Asp教程 来源:
导读:经常有这样的要求,根据不同的需求要求include不同的文件 。如各个人的不同设置,所以要求能动态include文件。 代码如下: Function include(filename) Dim re,content,fso,f,aspStart,aspEndset fso=CreateObject("

经常有这样的要求,根据不同的需求要求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") 

(编辑:银川站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章