根据需要动态include不同的文件
2002-09-18 09:08
459 查看
受<! #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")
必须存在该文件并且会预先编译(不管前面是否加以条件)
经常有这样的要求,根据不同的需求要求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")
相关文章推荐
- 对话#08:访问限制
- 对话#12:Abstract Factory, Template Style
- 对话#25:Getting to the Point
- 对话#26:A Midsummer Night’s Madness
- 对话#27:Baseless Exceptions
- 对话#28:Contracts, Promises, and Mere Semantics
- JS(Unicode->GB)的精简版(仍含拼音和UrlEncode)
- C++编译器怎么实现异常处理1
- 虚拟键码表(windows)
- 激活当前屏幕保护及获取网上计算机名及其IP地址
- 二零零二年IT业综述
- 无限级目录树最优算法的新研究
- Visual SourceSafe6.0 使用指南(二)
- Visual SourceSafe6.0 使用指南(一)
- VB.NET中对象的克隆
- ServeOneSocket.java 服务端源程序
- Java的中文编程与配置心得
- Js中实现拼音和UrlEncode的功能(利用GB和Unicode对照表)
- 透析Office
- 再探C++的单件实现