<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[静怡家园]]></title> 
<link>http://www.zhanghaijun.com/index.php</link> 
<description><![CDATA[书山有路勤为径，学海无涯苦作舟！]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[静怡家园]]></copyright>
<item>
<link>http://www.zhanghaijun.com/post//</link>
<title><![CDATA[对ASP动态包含文件方法的改进]]></title> 
<author>碟舞飞扬 &lt;webmaster@zhanghaijun.com&gt;</author>
<category><![CDATA[Web开发]]></category>
<pubDate>Sun, 26 Nov 2006 14:09:31 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//</guid> 
<description>
<![CDATA[ 
	ASP 本身不支持动态包含文件，现在的动态包含是通过 FSO 把被包含的文件合并到主文件里再运行。以下也有把形如 <html><br/><head><title>301 Moved Permanently</title></head><br/><body bgcolor="white"><br/><center><h1>301 Moved Permanently</h1></center><br/><hr><center>nginx</center><br/></body><br/></html><br/> 的普通包含文件方式称作“传统引用”，用函数实现的动态包含文件称作“动态引用”。常见的程序如下：<br/><br/>Function include(filename)<br/>Dim re,content,fso,f,aspStart,aspEnd<br/>set fso=CreateObject("Scripting.FileSystemObject")<br/>set f=fso.OpenTextFile(server.mappath(filename))<br/>content=f.ReadAll<br/>f.close<br/>set f=nothing<br/>set fso=nothing<br/>set re=new RegExp<br/>re.pattern="^&#92;s*="<br/>aspEnd=1<br/>aspStart=inStr(aspEnd,content,"<%")+2<br/>do while aspStart>aspEnd+1 <br/>Response.write Mid(content,aspEnd,aspStart-aspEnd-2)<br/>aspEnd=inStr(aspStart,content,"%&#92;>")+2<br/>Execute(re.replace(Mid(content,aspStart,aspEnd-aspStart-2),"Response.Write "))<br/>aspStart=inStr(aspEnd,content,"<%")+2<br/>loop<br/>Response.write Mid(content,aspEnd) <br/>set re=nothing<br/>End Function&nbsp;&nbsp;<br/>　　使用范例：include("youinc.asp")<br/><br/>　　但这处函数在处理补包含的文件中还有包含文件时就不灵了。我在以上函数的基础上改进出来如下函数，在被包含文件中还有普通的包含文件 <html><br/><head><title>301 Moved Permanently</title></head><br/><body bgcolor="white"><br/><center><h1>301 Moved Permanently</h1></center><br/><hr><center>nginx</center><br/></body><br/></html><br/> 也可正常运行。<br/><br/>Function includeconvert(oRegExp, strFilename, strBlock)<br/>Dim incStart, incEnd, match, oMatches, str, code<br/>'用提取ASP代码的相同方式提取出include 部分的文件名，其余部分原样输出<br/>code = ""<br/>incEnd = 1<br/>incStart = InStr(incEnd,strBlock,"<--#，incStart是从")+3<br/>oregExp.pattern="(&#92;w+)=""([^""]+)""" '匹配 file="filename.ext" 或 virtual="virtualname.ext"，捕捉类型及文件名两个子串<br/>Set oMatches = oregExp.Execute(Mid(strBlock,incStart,incEnd-incStart-3))<br/>Set match = oMatches(0) '确定只有一组捕捉时，要得到这一组匹配的子串，可以这样做，省去用 For Each match In oMatches …… Next<br/>code = code & include(Mid(strFilename, 1, InStrRev(strFilename, "/")) & match.SubMatches(1)) 'Mid(filename, 1, InStrRev(filename, "/")) 是在被引用的子文件名有路径时,把路径提取出来,加在子文件中传统引用的文件名前面,以找到正确的打开文件路径,因为动态引用时的文件路径是相对主文件而言的。要第二个匹配子串用SubMatches(1)<br/>incStart = InStr(incEnd,strBlock," 的普通包含文件方式称作“传统引用”，用函数实现的动态包含文件称作“动态引用”。常见的程序如下：<br/><br/>Function include(filename)<br/>Dim re,content,fso,f,aspStart,aspEnd<br/>set fso=CreateObject("Scripting.FileSystemObject")
]]>
</description>
</item><item>
<link>http://www.zhanghaijun.com/post//#blogcomment</link>
<title><![CDATA[[评论] 对ASP动态包含文件方法的改进]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.zhanghaijun.com/post//#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>