91网首页-91网页版-91网在线观看-91网站免费观看-91网站永久视频-91网站在线播放

LOGO OA教程 ERP教程 模切知識(shí)交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

asp動(dòng)態(tài)include文件

admin
2010年9月2日 14:45 本文熱度 4260
ASP 本身不支持動(dòng)態(tài)包含文件,現(xiàn)在的動(dòng)態(tài)包含是通過 FSO 把被包含的文件合并到主文件里再運(yùn)行。以下也有把形如 <!--#include file="filename.asp" --> 的普通包含文件方式稱作“傳統(tǒng)引用”,用函數(shù)實(shí)現(xiàn)的動(dòng)態(tài)包含文件稱作“動(dòng)態(tài)引用”。常見的程序如下: 

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")



  但這處函數(shù)在處理補(bǔ)包含的文件中還有包含文件時(shí)就不靈了。我在以上函數(shù)的基礎(chǔ)上改進(jìn)出來如下函數(shù),在被包含文件中還有普通的包含文件 <!--#include file="filename.asp" --> 也可正常運(yùn)行。



Function includeconvert(oRegExp, strFilename, strBlock)

Dim incStart, incEnd, match, oMatches, str, code

'用提取ASP代碼的相同方式提取出include 部分的文件名,其余部分原樣輸出

code = ""

incEnd = 1

incStart = InStr(incEnd,strBlock,"<!--#include ") + 13 '要找個(gè)目標(biāo)字符串<!--#include 正好是13個(gè)字符,所以要+13

Do While incStart>incEnd+12 '兩個(gè)引用間距最小就是連續(xù)的--><--#,incStart是從<!--#include起數(shù)13個(gè)字符,所以要比前一個(gè)incEnd要至少多 13-1 得到的>incEnd+12的條件

str = Mid(strBlock,incEnd,incStart-incEnd-13)

str = Replace(str, """", """""") '把單個(gè)雙引號(hào)換成兩個(gè)雙引號(hào)

str = Replace(str, VbCr, "")

str = Replace(str, VbLf, "")

str = Replace(str, VbCrLf, "")

code = code & VbCrLf & "Response.Write """ & str & """"

incEnd=InStr(incStart,strBlock,"-->")+3

oRegExp.pattern="(\w+)=""([^""]+)""" '匹配 file="filename.ext" 或 virtual="virtualname.ext",捕捉類型及文件名兩個(gè)子串

Set oMatches = oRegExp.Execute(Mid(strBlock,incStart,incEnd-incStart-3))

Set match = oMatches(0) '確定只有一組捕捉時(shí),要得到這一組匹配的子串,可以這樣做,省去用 For Each match In oMatches …… Next

code = code & include(Mid(strFilename, 1, InStrRev(strFilename, "/")) & match.SubMatches(1)) 'Mid(filename, 1, InStrRev(filename, "/")) 是在被引用的子文件名有路徑時(shí),把路徑提取出來,加在子文件中傳統(tǒng)引用的文件名前面,以找到正確的打開文件路徑,因?yàn)閯?dòng)態(tài)引用時(shí)的文件路徑是相對(duì)主文件而言的。要第二個(gè)匹配子串用SubMatches(1)

incStart = InStr(incEnd,strBlock,"<!--#include ")+13

Loop

str = Mid(strBlock,incEnd)

str = Replace(str, """", """""") '把單個(gè)雙引號(hào)換成兩個(gè)雙引號(hào)

str = Replace(str, VbCr, "")

str = Replace(str, VbLf, "")

str = Replace(str, VbCrLf, "")

code = code & VbCrLf & "Response.Write """ & str & """"

includeconvert = code

End Function

Function include(filename)

Dim re, content, fso, f, aspStart, aspEnd, code

Set fso=CreateObject("scripting.FileSystemObject")

Set f=fso.OpenTextFile(Server.MapPath(filename))

content=f.ReadAll

f.close

Set f=nothing

Set fso=nothing

code = ""

aspEnd=1

aspStart=InStr(aspEnd,content,"<%")+2

Set re=new RegExp

Do While aspStart>aspEnd+1

'傳統(tǒng)引用<!--#inclde 肯定是在ASP代碼段以外的,所以先轉(zhuǎn)。

code = code & includeconvert (re, filename, Mid(content,aspEnd,aspStart-aspEnd-2))

aspEnd=InStr(aspStart,content,"%\>")+2

re.pattern="^\s*=" '這段正則替換原來是把 <% = str % > 換回成標(biāo)準(zhǔn)的 <%Response.Write str % >

code = code & VbCrLf & re.replace(Mid(content,aspStart,aspEnd-aspStart-2),"Response.Write ") 'ASP塊前面再加回車換行,以避免連接塊之間多個(gè) Response.Write在同一行的錯(cuò)誤

aspStart=InStr(aspEnd,content,"<%")+2

Loop

code = code & includeconvert (re, filename, Mid(content,aspEnd))

Set re=nothing

include = code

End Function 



  方便起見,以上函數(shù)最終返回的是整合了包含文件的整個(gè) ASP 代碼,使用時(shí)還要再用 Execute 執(zhí)行之,即使用時(shí)需要:Execute(include("file.asp"))。



  以上函數(shù)對(duì)被包含文件與主文件同一路徑時(shí)測(cè)試通過,未對(duì)被包含文件與主文件路徑不同的情況做進(jìn)一步容錯(cuò),時(shí)間有限,歡迎有興趣的朋友提出意見和改進(jìn)。

該文章在 2010/9/2 15:01:28 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點(diǎn)晴ERP是一款針對(duì)中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國(guó)內(nèi)大量中小企業(yè)的青睞。
點(diǎn)晴PMS碼頭管理系統(tǒng)主要針對(duì)港口碼頭集裝箱與散貨日常運(yùn)作、調(diào)度、堆場(chǎng)、車隊(duì)、財(cái)務(wù)費(fèi)用、相關(guān)報(bào)表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點(diǎn),圍繞調(diào)度、堆場(chǎng)作業(yè)而開發(fā)的。集技術(shù)的先進(jìn)性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點(diǎn)晴WMS倉(cāng)儲(chǔ)管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購(gòu)管理,倉(cāng)儲(chǔ)管理,倉(cāng)庫(kù)管理,保質(zhì)期管理,貨位管理,庫(kù)位管理,生產(chǎn)管理,WMS管理系統(tǒng),標(biāo)簽打印,條形碼,二維碼管理,批號(hào)管理軟件。
點(diǎn)晴免費(fèi)OA是一款軟件和通用服務(wù)都免費(fèi),不限功能、不限時(shí)間、不限用戶的免費(fèi)OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 成人亚洲欧美 | 麻花传媒免费网 | 午夜福利二区 | 国产精国产精品 | 国产精品精品国 | 九一精品 | 日韩精品视频美在 | 午夜小视频网 | 欧美日韩亚洲第 | 区三区在线观看 | 国产欧美在线 | 中文字幕日韩wm | 欧洲+日本+中国 | 国产韩日欧美在线 | 日本在线不卡视频 | 欧美最猛性XXX | 日韩专区第一页 | 国产私拍 | 欧美亚洲国产福利 | 日韩好看中文字母 | 国产日韩欧美专区 | 国产日产欧美一区 | 97色精品| 精品国产中文 | 国产精品欧美日 | 国产精品广西柳州 | 日韩一级一区二区不 | 成人宗合 | 成人影院 | 国产日韩欧美专区 | 日韩欧美午夜电影 | 日本www.色| 国产丰满 | 国产h片在线观看 | 国产不卡视频 | 日韩ab在线播放 | 91精选一区在线 | 日韩欧美一级大片 | 乱婬真视频 | 欧美综合天天 | 国产精品免费大 |