asp動態(tài)include文件,方便多模板的實現(xiàn)
更新時間:2007年08月12日 14:43:19 作者:
受<! #include file="filename.asp" --> 宏限制,必須存在該文件并且會預先編譯(不管前面是否加以條件)
經(jīng)常有這樣的要求,根據(jù)不同的需求要求include不同的文件,如各個人的不同設置,所以要求能動態(tài)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")
經(jīng)常有這樣的要求,根據(jù)不同的需求要求include不同的文件,如各個人的不同設置,所以要求能動態(tài)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")
相關文章
ASP.NET?Core?5.0中的Host.CreateDefaultBuilder執(zhí)行過程解析
通過Rider調(diào)試的方式看了下ASP.NET Core 5.0的Web API默認項目,重點關注Host.CreateDefaultBuilder(args)中的執(zhí)行過程,主要包括主機配置、應用程序配置、日志配置和依賴注入配置這4個部分,需要的朋友可以參考下2022-08-08asp中去除內(nèi)容HTML標簽的三個function函數(shù)
asp中去除內(nèi)容HTML標簽的三個function函數(shù)...2007-03-03asp數(shù)據(jù)庫連接rs("user.id")
數(shù)據(jù)庫連接,有時會出錯在conn.open connstr這地方的問題,及聯(lián)接查詢調(diào)用rs("user.id")的問題2008-07-07ASP動態(tài)網(wǎng)頁制作技術經(jīng)驗分享
本文介紹的是ASP動態(tài)網(wǎng)頁制作技術的一些經(jīng)驗心得,主要從四個大的方面,給大家介紹的,需要的朋友可以參考下2015-10-10