精美而实用的网站,关注web编程技术、网站运营、SEO推广,让您轻松愉快的学习

在ASP中include文件形如 #include file=function.asp,这是最简单也是最常用的包含文件方法,青岛星网下面跟大家分享:根据不同的需求,包含不同的文件的函数。

ASP动态包含文件的实现函数

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("***.asp")'注意,这里的include是函数名哦,不要搞混哦。
Tags:ASP 函数