扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共19页)
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 |
Function includeconvert(oRegExp, strFilename, strBlock) Dim incStart, incEnd, match, oMatches, str, code '用提取ASP代码的相同方式提取出include 部分的文件名,其余部分原样输出 code = "" incEnd = 1 incStart = InStr(incEnd,strBlock,"<!--#include ") + 13 '要找个目标字符串<!--#include 正好是13个字符,所以要+13 Do While incStart>incEnd+12 '两个引用间距最小就是连续的--><--#,incStart是从<!--#include起数13个字符,所以要比前一个incEnd要至少多 13-1 得到的>incEnd+12的条件 str = Mid(strBlock,incEnd,incStart-incEnd-13) str = Replace(str, """", """""") '把单个双引号换成两个双引号 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",捕捉类型及文件名两个子串 Set oMatches = oRegExp.Execute(Mid(strBlock,incStart,incEnd-incStart-3)) Set match = oMatches(0) '确定只有一组捕捉时,要得到这一组匹配的子串,可以这样做,省去用 For Each match In oMatches …… Next code = code & include(Mid(strFilename, 1, InStrRev(strFilename, "/")) & match.SubMatches(1)) 'Mid(filename, 1, InStrRev(filename, "/")) 是在被引用的子文件名有路径时,把路径提取出来,加在子文件中传统引用的文件名前面,以找到正确的打开文件路径,因为动态引用时的文件路径是相对主文件而言的。要第二个匹配子串用SubMatches(1) incStart = InStr(incEnd,strBlock,"<!--#include ")+13 Loop str = Mid(strBlock,incEnd) str = Replace(str, """", """""") '把单个双引号换成两个双引号 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 '传统引用<!--#inclde 肯定是在ASP代码段以外的,所以先转。 code = code & includeconvert (re, filename, Mid(content,aspEnd,aspStart-aspEnd-2)) aspEnd=InStr(aspStart,content,"%\>")+2 re.pattern="^\s*=" '这段正则替换原来是把 <% = str % > 换回成标准的 <%Response.Write str % > code = code & VbCrLf & re.replace(Mid(content,aspStart,aspEnd-aspStart-2),"Response.Write ") 'ASP块前面再加回车换行,以避免连接块之间多个 Response.Write在同一行的错误 aspStart=InStr(aspEnd,content,"<%")+2 Loop code = code & includeconvert (re, filename, Mid(content,aspEnd)) Set re=nothing include = code End Function |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者