asp動(dòng)態(tài)include文件,方便多模板的實(shí)現(xiàn)
更新時(shí)間:2007年08月12日 14:43:19 作者:
受<! #include file="filename.asp" --> 宏限制,必須存在該文件并且會(huì)預(yù)先編譯(不管前面是否加以條件)
經(jīng)常有這樣的要求,根據(jù)不同的需求要求include不同的文件,如各個(gè)人的不同設(shè)置,所以要求能動(dòng)態(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不同的文件,如各個(gè)人的不同設(shè)置,所以要求能動(dòng)態(tài)include文件。
代碼如下:
復(fù)制代碼 代碼如下:
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
使用范例:
復(fù)制代碼 代碼如下:
include("youinc.asp")
相關(guān)文章
ASP上傳漏洞之利用CHR(0)繞過(guò)擴(kuò)展名檢測(cè)腳本
本文部分腳本具有攻擊性,僅供學(xué)習(xí)研究用,請(qǐng)用在合法合理范圍內(nèi),對(duì)造成的損失本人不承擔(dān)責(zé)任,本人也不提供黑客攻擊技術(shù)指導(dǎo)2012-01-01ASP.NET?Core?5.0中的Host.CreateDefaultBuilder執(zhí)行過(guò)程解析
通過(guò)Rider調(diào)試的方式看了下ASP.NET Core 5.0的Web API默認(rèn)項(xiàng)目,重點(diǎn)關(guān)注Host.CreateDefaultBuilder(args)中的執(zhí)行過(guò)程,主要包括主機(jī)配置、應(yīng)用程序配置、日志配置和依賴注入配置這4個(gè)部分,需要的朋友可以參考下2022-08-08asp中去除內(nèi)容HTML標(biāo)簽的三個(gè)function函數(shù)
asp中去除內(nèi)容HTML標(biāo)簽的三個(gè)function函數(shù)...2007-03-03asp自動(dòng)補(bǔ)全html標(biāo)簽自動(dòng)閉合(正則表達(dá)式)
asp自動(dòng)補(bǔ)全html標(biāo)簽自動(dòng)閉合,方便asp截取帶有html標(biāo)簽的內(nèi)容,防止頁(yè)面變形2012-10-10asp數(shù)據(jù)庫(kù)連接rs("user.id")
數(shù)據(jù)庫(kù)連接,有時(shí)會(huì)出錯(cuò)在conn.open connstr這地方的問(wèn)題,及聯(lián)接查詢調(diào)用rs("user.id")的問(wèn)題2008-07-07ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)經(jīng)驗(yàn)分享
本文介紹的是ASP動(dòng)態(tài)網(wǎng)頁(yè)制作技術(shù)的一些經(jīng)驗(yàn)心得,主要從四個(gè)大的方面,給大家介紹的,需要的朋友可以參考下2015-10-10