如何在ASP页面动态Inclue文件?

发布时间:2022-04-17 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了如何在ASP页面动态Inclue文件?脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
受<!&nbsp;#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.wrIT;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") 

脚本宝典总结

以上是脚本宝典为你收集整理的如何在ASP页面动态Inclue文件?全部内容,希望文章能够帮你解决如何在ASP页面动态Inclue文件?所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: