问一段asp的作用

来源:百度知道 编辑:UC知道 时间:2024/05/15 15:22:47
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

应该是输出文件的内容,并且过滤一些字符吧。。。

是用来动态加载文件的,因为asp自带的include包含的文件有一些缺陷,

即不管你是否需要,只要你用include引入了文件,那这个文件中的代码都会被执行。

比如这段代码:
<% if a=1 then %>
<!--include file="1.asp"-->
<%else%>
<!--include file="2.asp"-->
<% end if %>

理论上,你的目标应该是根据a变量值来载入1.asp或2.asp,

但是实际执行的时候,不管a的值是什么,都会载入1.asp和2.asp,

并不会按你的意图只载入1.asp或2.asp,

所以有人想出这个办法,自制一个include函数,来动态加载需要引用的文件并执行文件中的代码。

这样代码就变成了:

<%
if a=1 then
include("1.asp")
else
include("2.asp")
end if
%>

用来显示.asp include了哪些文件吧

读取asp这样类型的文件吧。。
然后输出