受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," 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," loop
Response.write Mid(content,aspEnd)
set re=nothing
End Function
使用范例:
include("youinc.asp")
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/10752043/viewspace-991784/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/10752043/viewspace-991784/
本文介绍了一种在ASP中实现动态include不同文件的方法,通过自定义函数实现文件内容的读取和执行,以此来满足根据不同需求加载不同配置或脚本的需求。

被折叠的 条评论
为什么被折叠?



