学习网考试学习资料

Gzu521.com

对ASP动态包含文件方法的改进(2)

ASP教程   点击:次   发布时间:2006-11-27   【字体: 】   来源:Gzu521.com
Gzu521.com我的学习网

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 

7($=fNBZL [ 此文转贴于 贵 州 学 习 网 网络编程ASP教程 http://WWW.gzu521.COM ] 7($=fNBZL


include = code 
end function  

  方便起见,以上函数最终返回的是整合了包含文件的整个 asp 代码,使用时还要再用 execute 执行之,即使用时需要:execute(include("file.asp"))。 

  以上函数对被包含文件与主文件同一路径时测试通过,未对被包含文件与主文件路径不同的情况做进一步容错,时间有限,欢迎有兴趣的朋友提出意见和改进。 

上 一 页
2页: 第 [1] [2]

责任编辑:gzu521

网络编程分类
ASP教程
.Net教程
Java教程
PHP教程
数据库基础
ACCESS教程
SQL Server教程
MySQL教程
Oracle教程
分类推荐信息
更多...
大类最新文章
更多...