fun.asp 模擬動態加載include的函數<%
Function qwbminclude(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
%>
time.asp 測試上面動態加載函數效果
<!--#include file="fun.asp"-->
<%
tid = "1"
response.write include(tid&".asp")
%>
1.asp 測試加載之后的效果
<!--#include file="fun.asp"-->
<h3><%=tid%></h3>
<h1>111111111111111111</h1>
<h2><%=now()%></h2>
<%response.write include("b.asp")%>
2.asp 測試加載之后的效果
<!--#include file="fun.asp"-->
<h3><%=tid%></h3>
<h1>22222222222222222</h1>
<h2><%=now()%></h2>
<%response.write include("b.asp")%>
b.asp 這個頁面是用來測試嵌套加載效果
<!--#include file="fun.asp"-->
現在時間:<hr>
<%=time()%><br />
<%=now()%><br />
<h3><%=tid%></h3>