游戏策划 入门指南 文案模板 游戏分析 系统架构 设计技巧 综合讨论 项目管理 市场运营
程序教程 程序入门 游戏编程 网络编程 窗口编程 人工智能 算法结构 引擎设计 引擎应用 图形渲染 物理系统 设计理论 算法结构 引擎设计 场景管理 脚本语言 移动平台
美术教程 美术基础 手绘教程 象素设计 PhotoShop Painter 3Dmax MAYA OpenCanvas 后期制作
对ASP 动态包含文件方法的改进
对ASP 动态包含文件方法的改进
ASP 本身不支持动态包含文件,现在的动态包含是通过 FSO 把被包含的文件合并到主文件里再运行。以下也有把形如 的普通包含文件方式称作“传统引用”,用函数实现的动态包含文件称作“动态引用”。常见的程序如下:
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")
以上范例引自 http://www.blueidea.com/tech/program/2003/101.asp
但这处函数在处理补包含的文件中还有包含文件时就不灵了。我在以上函数的基础上改进出来如下函数,在被包含文件中还有普通的包含文件 也可正常运行。
Function includeconvert(oRegExp, strFilename, strBlock)
Dim incStart, incEnd, match, oMatches, str, code
'用提取ASP代码的相同方式提取出include 部分的文件名,其余部分原样输出
code = ""
incEnd = 1
incStart = InStr(incEnd,strBlock,"<--#,incStart是从")+3
oRegExp.pattern="(\w+)=""([^""]+)""" '匹配 file="filename.ext" 或 virtual="virtualname.ext",捕捉类型及文件名两个子串
Set oMatches = oRegExp.Execute(Mid(strBlock,incStart,incEnd-incStart-3))
Set match = oMatches(0) '确定只有一
标签TAG:对ASP 动态包含文件方法的改进。
打印本文
对ASP 动态包含文件方法的改进 |
||