<?xml version="1.0" encoding="UTF-8"?>

<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="html"><![CDATA[柏文，别说不可能]]></title>
  <subtitle type="html"><![CDATA[柏文，别说不可能]]></subtitle>
  <id>http://www.9702.com.cn/</id>
  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/" /> 
  <link rel="self" type="application/atom+xml" href="http://www.9702.com.cn/atom.asp" /> 
  <generator uri="http://www.MosquitoWeb.cn/" version="3.0">网站后台管理系统 V3.0(MosquitoWeb 3.0d)</generator> 
  <updated>2008-11-21 18:40:17</updated>

  <entry>
	  <title type="html"><![CDATA[MosquitoWeb V3.0 最新版 模板样式]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=400" label="MosquitoWeb V3.0 最新版 模板样式" /> 
	  <updated>2008-11-21 18:23:12</updated>
	  <published>2008-11-21 18:23:12</published>
		  <summary type="html"><![CDATA[<p>1.文件夹的命名尽量为：你的标识_模板名称<br />2.模板文件夹内应包含模板缩略图 p.gif 100*100<br />3.模板文件夹内应包含模板缩略图 p.xml 表示模板的相关信息，具体说明如下：</p>
<p>&nbsp;&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&nbsp;&lt;dfcms&gt; <br />&nbsp;&lt;name&gt;模板名称&lt;/name&gt;<br />&nbsp;&lt;author&gt;模板的作者&lt;/author&gt;<br />&nbsp;&lt;info&gt;版权信息及相关说明&lt;/info&gt;<br />&nbsp;&lt;/dfcms&gt;</p>
<p>4.所有文件统一采用UTF-8编码</p>
<p>5.文件功能：<br />&nbsp;t.gif&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;模板缩略图<br />&nbsp;t.xml&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;模板配置相关信息<br />&nbsp;content.html&nbsp;&nbsp;&nbsp;内容HTML页<br />&nbsp;footer.html&nbsp;&nbsp;&nbsp;&nbsp;网上底部HTML代码<br />&nbsp;left.html&nbsp;&nbsp;&nbsp;&nbsp;网站左侧HTMl代码<br />&nbsp;newsdetail.html&nbsp;&nbsp;&nbsp;新闻明细页<br />&nbsp;newslist.html&nbsp;&nbsp;&nbsp;新闻列表页<br />&nbsp;outherdetail.html&nbsp;&nbsp;其它类明细页<br />&nbsp;outherlist.html&nbsp;&nbsp;&nbsp;其它类列表页<br />&nbsp;productdetail.html&nbsp;&nbsp;产品明细页<br />&nbsp;productlist.html&nbsp;&nbsp;产品列表页<br />&nbsp;top.html&nbsp;&nbsp;&nbsp;&nbsp;网站头部HTML代码</p>
<p>6.标签定义<br />&nbsp;------页面类------<br />&nbsp;{{pageTop}}&nbsp;&nbsp;&nbsp;&nbsp;头部页<br />&nbsp;{{pageLeft}}&nbsp;&nbsp;&nbsp;左侧页<br />&nbsp;{{pageFooter}}&nbsp;&nbsp;&nbsp;底部页<br />&nbsp;<br />&nbsp;------变量类------<br />&nbsp;{{tmpPath}}&nbsp;&nbsp;&nbsp;&nbsp;模板路径<br />&nbsp;{{tmpComTitle}}&nbsp;&nbsp;&nbsp;单位名称<br />&nbsp;{{tmpComAddress}}&nbsp;&nbsp;单位地址&nbsp;<br />&nbsp;{{tmpComTel}}&nbsp;&nbsp;&nbsp;单位电话<br />&nbsp;{{tmpComFax}}&nbsp;&nbsp;&nbsp;单位传真<br />&nbsp;{{tmpWebTitle}}&nbsp;&nbsp;&nbsp;网站名称<br />&nbsp;{{tmpWebUrl}}&nbsp;&nbsp;&nbsp;网站地址<br />&nbsp;{{tmpWebICP}}&nbsp;&nbsp;&nbsp;网站ICP备案<br />&nbsp;{{tmpWebHits}}&nbsp;&nbsp;&nbsp;网站点击次数<br />&nbsp;{{tmpDescription}}&nbsp;&nbsp;网站Mate信息<br />&nbsp;{{tmpKeywords}}&nbsp;&nbsp;&nbsp;网站Mate信息<br />&nbsp;{{tmpLocation}}&nbsp;&nbsp;&nbsp;我的当前位置<br />&nbsp;<br />&nbsp;------函数类------<br />&nbsp;{{funMenu}}&nbsp;&nbsp;&nbsp;&nbsp;定义一个导航栏<br />&nbsp;{{funNewsClass}}&nbsp;&nbsp;定义一个新闻分类<br />&nbsp;{{funProductClass}}&nbsp;&nbsp;定义一个产品分类<br />&nbsp;{{funListPage}}&nbsp;&nbsp;&nbsp;定义一个分页<br />&nbsp;{{funChannelTitle}}&nbsp;&nbsp;定义一个栏目标题<br />&nbsp;{{funChannelContent}}&nbsp;定义一个栏目内容<br />&nbsp;<br />&nbsp;{{funListTitle}}&nbsp;&nbsp;定义一个明细标题<br />&nbsp;{{funListPicBig}}&nbsp;&nbsp;定义一个明细大图<br />&nbsp;{{funListContent}}&nbsp;&nbsp;定义一个明细内容<br />&nbsp;{{funListFile}}&nbsp;&nbsp;&nbsp;定义一个明细附件<br />&nbsp;{{funListHits}}&nbsp;&nbsp;&nbsp;定义一个明细点击数<br />&nbsp;{{funListAddTime}}&nbsp;&nbsp;定义一个明细添加时间<br />&nbsp;{{funListAddUser}}&nbsp;&nbsp;定义一个明细添加人员<br />&nbsp;{{funListExt}}&nbsp;&nbsp;&nbsp;定义一组附加属性</p>]]></summary>
	  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/myBlog.asp?s=400" /> 
	  <id>http://www.9702.com.cn/myBlog.asp?a=400</id>
  </entry>	
		
  <entry>
	  <title type="html"><![CDATA[云南行图片]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=399" label="云南行图片" /> 
	  <updated>2008-11-13 10:25:36</updated>
	  <published>2008-11-13 10:25:36</published>
		  <summary type="html"><![CDATA[<img alt="" src="../../Upload/2008-11-13/zmKp5TPM_DSC01439.jpg" /><br /><br /><img alt="" src="../../Upload/2008-11-13/DsbU57Pe_DSC01477.jpg" /><br /><br /><img alt="" src="../../Upload/2008-11-13/SKeq0ifa_DSC01522.jpg" /><br /><br /><img alt="" src="../../Upload/2008-11-13/zwQmQs11_IMG_1048.jpg" /><br /><br /><a href="http://baiwen.5166.info/index.do" target="_blank">更多点击&gt;&gt;&gt;</a>]]></summary>
	  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/myBlog.asp?s=399" /> 
	  <id>http://www.9702.com.cn/myBlog.asp?a=399</id>
  </entry>	
		
  <entry>
	  <title type="html"><![CDATA[使用模板实现ASP代码与页面分离]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=398" label="使用模板实现ASP代码与页面分离" /> 
	  <updated>2008-11-2 17:00:19</updated>
	  <published>2008-11-2 17:00:19</published>
		  <summary type="html"><![CDATA[<p>每个进行过较大型的ASP-Web应用程序设计的开发人员大概都有如下的经历：ASP代码与页面HTML混淆难分，业务逻辑与显示方式绞合，使得代码难以理解、难以修改；程序编写必须在美工之后，成为项目瓶颈；整合的程序代码和HTML静态页面时，花费大量的时间才能得到理想的效果，兼作了美工。的确，用脚本语言开发Web应用不容易将数据的处理和数据的显示分开，但在多人合作的情况下，如果无法将数据和显示分开，将大大影响开发的效率，专业分工的发挥。</p>
<p>其它的脚本语言，如JSP、PHP都有自己的解决方案，ASP的后一代产品ASP.NET也实现了代码与页面，似乎直接过渡到ASP是不错的选择。但是总有这样或那样的原因让我们不能或暂时不能放弃ASP直奔.NET大营。从公司角度来看，转换语言是一笔不少的投资，包括雇佣熟手.NET程序员、培训原有程序员、开发工具的转型、开发风格的转型、界面风格转变、接口风格、软件架构、文档、开发流程等等；这还意味着原有的代码必须在新语言环境里重写以实现最佳的效果和稳定性；同时将直接影响这段时间内项目的进度，更有可能导致个别程序员出走。由此看来在您决定转换语言之前，在原基础上寻求一种解决方案，才是最好的选择。</p>
<p>PHP通过模板实现代码与页面，可供选择的有FastTemplate、PHPLIB、Smarty等多种，其中PHPLIB的影响最大、使用最多。既然如此，我们直接把它搬到ASP来，对于同时使用PHP和ASP的公司还有很有好处：一、美工处理页面时，不管将要套用PHP还是ASP，处理方式是一样，无须经过培训；二、程序员编写代码时，两种语言间的思路接近或一致，相同功能在两种语言实现时，只需拷贝过来略作修改即可，保证了工作效率和项目进度。</p>
<p><strong>1、模板类的设计</strong></p>
<p>实现代码封装成为模板类，即是为了与PHPLIB兼容，也使得代码方便管理与扩展。<br />模板类要实现的目标为：从模板文件中读入显示的HTML代码，将这些显示代码中需要动态数据的地方替换为ASP程序运算所得出的数据，然后按照一定的顺序输出。其中，替换的部分可以自由的设定。因此它必须完成如下任务：<br /><br />&nbsp;&nbsp;&nbsp;&nbsp; &middot;从模板文件中读取显示用的HTML代码。<br />&nbsp;&nbsp;&nbsp;&nbsp; &middot;将模板文件和实际生成的数据结合，生成输出的结果。<br />&nbsp;&nbsp;&nbsp;&nbsp; &middot;允许同时处理多个模板。<br />&nbsp;&nbsp;&nbsp;&nbsp; &middot;允许模板的嵌套。<br />&nbsp;&nbsp;&nbsp;&nbsp; &middot;允许对模板中的某个单独的部分进行处理。</p>
<p><strong>实现方法：</strong><br /><br />采用FSO读取模板文件<br />采用正则替换实现模板文件和数据的结合<br />处理多个模板用数组存储来实现。</p>
<p>模板的嵌套的实现主要的想法是：将模板和输出（任何中间的分析结果）一视同仁，都可拿来做替换，即可实现。</p>
<p>单独部分的处理的通过在模板文件中设定标注，然后在正则替换中结合标注来控制，实现部分替换。</p>
<p><strong>2、模板类的实现</strong></p>
<p>给出具体代码之前，先把主要函数列出，用过PHPLIB的朋友应该对此很熟悉了：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />1）Public Sub set_root(ByVal Value)　设定模板默认目录<br />2）Public Sub set_file(ByVal handle,ByVal&nbsp;&nbsp; filename)　读取文件<br />3）Public Sub set_var(ByVal Name, ByVal Value, ByVal Append)　设置映射数据-替换变量<br />4）Public Sub unset_var(ByVal Name)　取消数据映射<br />5）Public Sub set_block(ByVal Parent, ByVal BlockTag, ByVal Name)　设置数据块<br />6）Public Sub set_unknowns(ByVal unknowns)　设定未指定映射的标记处理方式<br />7）Public Sub parse(ByVal Name, ByVal BlockTag, ByVal Append)　执行模板文件与数据的结合<br />8）Public Sub p(ByVal Name)　输出处理结果</td>
        </tr>
    </tbody>
</table>
</p>
<p><strong>实现代码：</strong></p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;%<br />'================================================================<br />' CLASS NAME:&nbsp;&nbsp; kktTemplate ASP页面模板对象<br />' DESIGN BY :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 彭国辉<br />' DATE:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2004-07-05<br />' WEBSITE:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http://kacarton.yeah.net/<br />' BLOG:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; http://blog.csdn.net/nhconch<br />' EMAIL:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kacarton@sohu.com<br />'<br />' 本对象中使用了set_var、set_block等命名方法是为了兼容phplib<br />'文章为作者原创，转载前请先与本人联系，转载请注明文章出处、保留作者信息，谢谢支持！<br />'================================================================<br /><br />Class kktTemplate<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Private m_FileName, m_Root, m_Unknowns, m_LastError, m_HaltOnErr<br />&nbsp;&nbsp;&nbsp;&nbsp; Private m_ValueList, m_BlockList<br />&nbsp;&nbsp;&nbsp;&nbsp; Private m_RegExp&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; ' 构造函数<br />&nbsp;&nbsp;&nbsp;&nbsp; Private Sub Class_Initialize<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set m_ValueList&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = CreateObject(&quot;Scripting.Dictionary&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set m_BlockList&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = CreateObject(&quot;Scripting.Dictionary&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set m_RegExp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = New RegExp<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_RegExp.IgnoreCase = True<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_RegExp.Global&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = True<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_FileName&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_Root&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_Unknowns&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;remove&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_LastError&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = &quot;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_HaltOnErr&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = true<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; ' 析构函数<br />&nbsp;&nbsp;&nbsp;&nbsp; Private Sub Class_Terminate<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set m_RegExp&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = Nothing<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set m_BlockMatches = Nothing<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set m_ValueMatches = nothing<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Property Get ClassName()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ClassName = &quot;kktTemplate&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp; End Property<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Property Get Version()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Version = &quot;1.0&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp; End Property<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub About()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(&quot;kktTemplate ASP页面模板类&lt;br&gt;&quot; &amp; vbCrLf &amp;_<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;程序设计：彭国辉 2004-07-05&lt;br&gt;&quot; &amp; vbCrLf &amp;_<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;个人网站：&lt;a href='http://kacarton.yeah.net'&gt;http://kacarton.yeah.net&lt;/a&gt;&lt;br&gt;&quot; &amp; vbCrLf &amp;_<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &quot;电子邮件：&lt;a href='mailto:kacarton@sohu.com'&gt;kacarton@sohu.com&lt;/a&gt;&lt;br&gt;&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; '检查目录是否存在<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Function FolderExist(ByVal path)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim fso<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; FolderExist = fso.FolderExists(Server.MapPath(path))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set fso = Nothing<br />&nbsp;&nbsp;&nbsp;&nbsp; End Function<br />&nbsp;&nbsp;&nbsp;&nbsp; '读取文件内容<br />&nbsp;&nbsp;&nbsp;&nbsp; Private Function LoadFile()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Filename, fso, hndFile<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Filename = m_Root<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Right(Filename, 1)&lt;&gt;&quot;/&quot; And Right(Filename, 1)&lt;&gt;&quot;\&quot; Then Filename = Filename &amp; &quot;/&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Filename = Server.MapPath(Filename &amp; m_FileName)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not fso.FileExists(Filename) Then ShowError(&quot;模板文件&quot; &amp; m_FileName &amp; &quot;不存在!&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set hndFile = fso.OpenTextFile(Filename)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LoadFile = hndFile.ReadAll<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set hndFile = Nothing<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Set fso = Nothing<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LoadFile = &quot;&quot; Then ShowError(&quot;不能读取模板文件&quot; &amp; m_FileName &amp; &quot;或文件为空!&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp; End Function<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; '处理错误信息<br />&nbsp;&nbsp;&nbsp;&nbsp; Private Sub ShowError(ByVal msg)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_LastError = msg<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write &quot;&lt;font color=red style='font-size;14px'&gt;&lt;b&gt;模板错误：&quot; &amp; msg &amp; &quot;&lt;/b&gt;&lt;/font&gt;&lt;br&gt;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If m_HaltOnErr Then Response.End<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; '设置模板文件默认目录<br />&nbsp;&nbsp;&nbsp;&nbsp; 'Ex: kktTemplate.set_root(&quot;/tmplate&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp; '&nbsp;&nbsp;&nbsp;&nbsp; kktTemplate.Root = &quot;/tmplate&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp; '&nbsp;&nbsp;&nbsp;&nbsp; root = kktTemplate.get_root()<br />&nbsp;&nbsp;&nbsp;&nbsp; '&nbsp;&nbsp;&nbsp;&nbsp; root = kktTemplate.Root<br />&nbsp;&nbsp;&nbsp;&nbsp; '使用类似set_root这样的命名方法是为了兼容phplib，以下将不再重复说明<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub set_root(ByVal Value)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not FolderExist(Value) Then ShowError(Value &amp; &quot;不是有效目录或目录不存在!&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_Root = Value<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Function get_root()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get_root = m_Root<br />&nbsp;&nbsp;&nbsp;&nbsp; End Function<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Property Let Root(ByVal Value)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set_root(Value)<br />&nbsp;&nbsp;&nbsp;&nbsp; End Property<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Property Get Root()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Root = m_Root<br />&nbsp;&nbsp;&nbsp;&nbsp; End Property<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; '设置模板文件<br />&nbsp;&nbsp;&nbsp;&nbsp; 'Ex: kktTemplate.set_file(&quot;hndTpl&quot;, &quot;index.htm&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp; '本类不支持多模板文件，handle为兼容phplib而保留<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub set_file(ByVal handle,ByVal&nbsp;&nbsp; filename)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_FileName = filename<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_BlockList.Add Handle, LoadFile()<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Function get_file()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get_file = m_FileName<br />&nbsp;&nbsp;&nbsp;&nbsp; End Function<br />'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Public Property Let File(handle, filename)<br />'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set_file handle, filename<br />'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Property<br />'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Public Property Get File()<br />'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; File = m_FileName<br />'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Property<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; '设置对未指定的标记的处理方式，有keep、remove、comment三种<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub set_unknowns(ByVal unknowns)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_Unknowns = unknowns<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Function get_unknowns()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; get_unknowns = m_Unknowns<br />&nbsp;&nbsp;&nbsp;&nbsp; End Function<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Property Let Unknowns(ByVal unknown)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_Unknowns = unknown<br />&nbsp;&nbsp;&nbsp;&nbsp; End Property<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Property Get Unknowns()<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Unknowns = m_Unknowns<br />&nbsp;&nbsp;&nbsp;&nbsp; End Property<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub set_block(ByVal Parent, ByVal BlockTag, ByVal Name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Matches<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_RegExp.Pattern = &quot;&lt;!--\s+BEGIN &quot; &amp; BlockTag &amp; &quot;\s+--&gt;([\s\S.]*)&lt;!--\s+END &quot; &amp; BlockTag &amp; &quot;\s+--&gt;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not m_BlockList.Exists(Parent) Then ShowError(&quot;未指定的块标记&quot; &amp; Parent)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set Matches = m_RegExp.Execute(m_BlockList.Item(Parent))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For Each Match In Matches<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_BlockList.Add BlockTag, Match.SubMatches(0)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_BlockList.Item(Parent) = Replace(m_BlockList.Item(Parent), Match.Value, &quot;{&quot; &amp; Name &amp; &quot;}&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set Matches = nothing<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub set_var(ByVal Name, ByVal Value, ByVal Append)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Val<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If IsNull(Value) Then Val = &quot;&quot; Else Val = Value<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If m_ValueList.Exists(Name) Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Append Then m_ValueList.Item(Name) = m_ValueList.Item(Name) &amp; Val _<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else m_ValueList.Item(Name) = Val<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_ValueList.Add Name, Value<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub unset_var(ByVal Name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If m_ValueList.Exists(Name) Then m_ValueList.Remove(Name)<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Private Function InstanceValue(ByVal BlockTag)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim keys, i<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InstanceValue = m_BlockList.Item(BlockTag)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; keys = m_ValueList.Keys<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i=0 To m_ValueList.Count-1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InstanceValue = Replace(InstanceValue, &quot;{&quot; &amp; keys(i) &amp; &quot;}&quot;, m_ValueList.Item(keys(i)))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp;&nbsp;&nbsp; End Function<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub parse(ByVal Name, ByVal BlockTag, ByVal Append)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not m_BlockList.Exists(BlockTag) Then ShowError(&quot;未指定的 块标记&quot; &amp; Parent)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If m_ValueList.Exists(Name) Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Append Then m_ValueList.Item(Name) = m_ValueList.Item(Name) &amp; InstanceValue(BlockTag) _<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else m_ValueList.Item(Name) = InstanceValue(BlockTag)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_ValueList.Add Name, InstanceValue(BlockTag)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Private Function finish(ByVal content)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select Case m_Unknowns<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;keep&quot; finish = content<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;remove&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_RegExp.Pattern = &quot;\{[^ \t\r\n}]+\}&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finish = m_RegExp.Replace(content, &quot;&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;comment&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; m_RegExp.Pattern = &quot;\{([^ \t\r\n}]+)\}&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; finish = m_RegExp.Replace(content, &quot;&lt;!-- Template Variable $1 undefined --&gt;&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Else finish = content<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Select<br />&nbsp;&nbsp;&nbsp;&nbsp; End Function<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; Public Sub p(ByVal Name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Not m_ValueList.Exists(Name) Then ShowError(&quot;不存在的标记&quot; &amp; Name)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(finish(m_ValueList.Item(Name)))<br />&nbsp;&nbsp;&nbsp;&nbsp; End Sub<br />End Class<br />%&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p><strong>3、使用例子</strong></p>
<p>下面举三个例子进行说明。</p>
<p><strong>1)简单的值替换</strong></p>
<p>模板文件为myTemple.tpl，内容：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;html&gt;&lt;title&gt;ASP模板简单替换&lt;/title&gt;&lt;body&gt;<br />祝贺！你赢了一辆{some_color}法拉利！<br />&lt;/body&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p>下面是ASP代码（kktTemplate.inc.asp就是上面给出的模板类）：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;!--#INCLUDE file=&quot;kktTemplate.inc.asp&quot;--&gt;<br />&lt;%<br />dim my_color, kkt<br />my_color = &quot;红色的&quot;<br />set kkt = new kktTemplate&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '创建模板对象<br />kkt.set_file &quot;hndKktTemp&quot;, &quot;myTemple.tpl&quot; '设置并读取模板文件myTemple.tpl<br />kkt.set_var &quot;some_color&quot;, my_color, false '设置模板变量 some_color = my_color的值<br />kkt.parse &quot;out&quot;, &quot;hndKktTemp&quot;, false&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '模板变量 out = 处理后的文件<br />kkt.p &quot;out&quot;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '输出out的内容<br />set kkt = nothing&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; '销毁模板对象<br />%&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p>执行后输出为：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;html&gt;&lt;title&gt;ASP模板简单替换&lt;/title&gt;&lt;body&gt;<br />祝贺！你赢了一辆红色的法拉利！<br />&lt;/body&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p><strong>2)循环块演示例子</strong></p>
<p>模板文件myTemple2.tpl：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;html&gt;&lt;title&gt;ASP模板－块的演示&lt;/title&gt;&lt;body&gt;<br />&lt;table cellspacing=&quot;2&quot; border=&quot;1&quot;&gt;&lt;tr&gt;&lt;td&gt;下面的动物您喜欢哪一种&lt;/td&gt;&lt;/tr&gt;<br />&lt;!-- BEGIN AnimalList --&gt;<br />&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;chk&quot;&gt;{animal}&lt;/td&gt;&lt;/tr&gt;<br />&lt;!-- END AnimalList --&gt;<br />&lt;/table&gt;<br />&lt;/body&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p><strong>ASP代码：</strong></p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;!--#INCLUDE file=&quot;kktTemplate.inc.asp&quot;--&gt;<br />&lt;%<br />dim animal, kkt, i<br />animal = Array(&quot;小猪&quot;,&quot;小狗&quot;,&quot;小强&quot;)<br />set kkt = new kktTemplate<br />kkt.set_file &quot;hndKktTemp&quot;, &quot;myTemple2.tpl&quot;<br />kkt.set_block &quot;hndKktTemp&quot;, &quot;AnimalList&quot;, &quot;list&quot;<br />for i=0 to UBound(animal)<br />&nbsp;&nbsp;&nbsp;&nbsp; kkt.set_var &quot;animal&quot;, animal(i), false<br />&nbsp;&nbsp;&nbsp;&nbsp; kkt.parse &quot;list&quot;, &quot;AnimalList&quot;, true<br />next<br />kkt.parse &quot;out&quot;, &quot;hndKktTemp&quot;, false<br />kkt.p &quot;out&quot;<br />set kkt = nothing<br />%&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p>执行结果：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;html&gt;&lt;title&gt;ASP模板－块的演示&lt;/title&gt;&lt;body&gt;<br />&lt;table cellspacing=&quot;2&quot; border=&quot;1&quot;&gt;&lt;tr&gt;&lt;td&gt;下面的动物您喜欢哪一种&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;chk&quot;&gt;小猪&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;chk&quot;&gt;小狗&lt;/td&gt;&lt;/tr&gt;<br />&lt;tr&gt;&lt;td&gt;&lt;input type=&quot;radio&quot; name=&quot;chk&quot;&gt;小强&lt;/td&gt;&lt;/tr&gt;<br />&lt;/table&gt;<br />&lt;/body&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p><strong>3)嵌套块演示</strong></p>
<p>模板文件myTemple3.tpl：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;html&gt;&lt;title&gt;ASP模板－嵌套块演示&lt;/title&gt;<br />&lt;body&gt;&lt;table width=&quot;400&quot; border=&quot;1&quot; bordercolor=&quot;#000000&quot;&gt;<br />&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;{myname}测试&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;我的动植物园：&lt;/td&gt; &lt;/tr&gt;<br />&lt;!-- BEGIN animalList --&gt;<br />&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;{animal}&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp; &lt;!-- BEGIN plantList --&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;{plant}&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp; &lt;!-- END plantList --&gt;<br />&lt;!-- END animalList --&gt;<br />&lt;/table&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p>ASP代码：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;!--#INCLUDE file=&quot;kktTemplate.inc.asp&quot;--&gt;<br />&lt;%<br />dim my_color, kkt, myname, animal, plant<br />set kkt = new kktTemplate<br />myname = &quot;kktTemplate block test...&quot;<br />animal = array(&quot;动物&quot;, &quot;植物&quot;)<br />plant&nbsp;&nbsp; = array(array(&quot;小猪&quot;,&quot;小白&quot;,&quot;小强&quot;), array(&quot;玫瑰&quot;,&quot;向日葵&quot;))<br /><br />kkt.set_file &quot;hndKktTemp&quot;, &quot;myTemple3.tpl&quot;<br />kkt.set_var &quot;myname&quot;, myname, false<br />kkt.set_block &quot;hndKktTemp&quot;, &quot;animalList&quot;, &quot;a&quot;<br />kkt.set_block &quot;animalList&quot;, &quot;plantList&quot;, &quot;p&quot;<br /><br />for i=0 to UBound(animal)<br />&nbsp;&nbsp;&nbsp; kkt.set_var &quot;animal&quot;, animal(i), False<br />&nbsp;&nbsp;&nbsp; kkt.unset_var &quot;p&quot; <br />&nbsp;&nbsp;&nbsp; 'kkt.set_var &quot;p&quot;, &quot;&quot;, false<br />&nbsp;&nbsp;&nbsp; for j=0 to UBound(plant(i))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kkt.set_var &quot;plant&quot;, plant(i)(j), false<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; kkt.parse &quot;p&quot;, &quot;plantList&quot;, true<br />&nbsp;&nbsp;&nbsp; next<br />&nbsp;&nbsp;&nbsp; kkt.parse &quot;a&quot;, &quot;animalList&quot;, true<br />next<br />kkt.parse &quot;out&quot;, &quot;hndKktTemp&quot;, false<br />kkt.p &quot;out&quot;<br />%&gt;</td>
        </tr>
    </tbody>
</table>
<br /><br />执行结果：</p>
<p>
<table style="BORDER-RIGHT: #cccccc 1px dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellspacing="0" cellpadding="6" width="95%" align="center" border="0">
    <tbody>
        <tr>
            <td style="WORD-WRAP: break-word" bgcolor="#fdfddf"><br />&lt;html&gt;&lt;title&gt;ASP模板－嵌套块演示&lt;/title&gt;<br />&lt;body&gt;&lt;table width=&quot;400&quot; border=&quot;1&quot; bordercolor=&quot;#000000&quot;&gt;<br />&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;&lt;div align=&quot;center&quot;&gt;kktTemplate block test...测试&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;我的动植物园：&lt;/td&gt; &lt;/tr&gt;<br />&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;动物&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;小猪&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;小白&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;小强&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;植物&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;玫瑰&lt;/td&gt;&lt;/tr&gt;<br />&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;&lt;td&gt;&amp;nbsp;&amp;nbsp;向日葵&lt;/td&gt;&lt;/tr&gt;<br />&lt;/table&gt;<br />&lt;/body&gt;<br />&lt;/html&gt;</td>
        </tr>
    </tbody>
</table>
</p>
<p><strong>4、小结</strong></p>
<p>本文主要介绍了基于ASP利用模板类实现代码与页面分离的方法，当然还有其它更好的解决方案。本文旨在抛砖引玉各位读者、WEB开发参与进来，多提宝贵意见，多作交流，共同进步！</p>]]></summary>
	  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/myBlog.asp?s=398" /> 
	  <id>http://www.9702.com.cn/myBlog.asp?a=398</id>
  </entry>	
		
  <entry>
	  <title type="html"><![CDATA[asp模板解析类模块（支持if，function，loop及解析缓存）]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=397" label="asp模板解析类模块（支持if，function，loop及解析缓存）" /> 
	  <updated>2008-11-2 16:50:01</updated>
	  <published>2008-11-2 16:50:01</published>
		  <summary type="html"><![CDATA[<p>&lt;%</p>
<p>Class Cls_Template</p>
<p>Dim Reg<br />Dim Page<br />Dim CID<br />Dim SID<br />Dim Rule<br />Dim Content<br />Dim Template<br />Dim Cachetimei<br /><br />Private Sub Class_Initialize()<br />Set Reg = New RegExp<br />Reg.Ignorecase = True<br />Reg.Global = True<br />Page = 0<br />CID = 0<br />SID = 0<br />Rule = &quot;&quot;<br />Content = &quot;&quot;<br />Template = &quot;&quot; ' 模板路径<br />Cachetimei = -1 ' 标签缓存时间<br />End Sub<br /><br />Private Sub Class_Terminate()<br />'Set Reg = Nothing<br />End Sub</p>
<p>' 载入模板<br />Public Function Load(ByVal Templatefile)<br />Template = Templatefile<br />If Templatecache = 1 Then<br />&nbsp;&nbsp; If ChkCache(&quot;LoadTemplate_&quot; &amp; Server.Mappath(Template)) Then<br />&nbsp;&nbsp;&nbsp; Content = GetCache(&quot;LoadTemplate_&quot; &amp; Server.Mappath(Template))<br />&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp; Call Loadfile<br />&nbsp;&nbsp;&nbsp; Call SetCache(&quot;LoadTemplate_&quot; &amp; Server.Mappath(Template), Content)<br />&nbsp;&nbsp; End If<br />Else<br />&nbsp;&nbsp; Call Loadfile<br />End If<br />End Function<br /><br />' 检测SQL缓存<br />Function ChkCacheSQL(ByVal CacheName)<br />If Cachetimei &lt;= 0 Then ChkCacheSQL = False: Exit Function<br />Dim CacheData<br />ChkCacheSQL = False<br />CacheName = LCase(Filterstr(CacheName))<br />CacheData = Application(Cacheflag &amp; CacheName)<br />If Not IsArray(CacheData) Then Exit Function<br />If Not IsDate(CacheData(1)) Then Exit Function<br />If DateDiff(&quot;s&quot;, CDate(CacheData(1)), Now()) &lt; 60 * Cachetime Then ChkCacheSQL = True<br />End Function</p>
<p>' 标签分析,有缓存有效期判断<br />Public Function Parser()<br />If Not IsNumeric(Page) Then Page = 0 Else Page = Int(Page)<br />Parser_My ' 自定义标签<br />Parser_Sys ' 系统标签<br />Parser_Com ' 列表标签<br />Parser_IF ' IF ELSE END<br />End Function<br /><br />' 自定义标签<br />Public Function Parser_My()<br />On Error Resume Next<br />If GetCache(&quot;MyLableState&quot;) = &quot;No&quot; Then Content = RegReplace(Content, &quot;{My:([\s\S]*?)}&quot;, &quot;&quot;): Exit Function<br />If Not ChkCache(&quot;MyLable&quot;) Then<br />&nbsp;&nbsp; Dim Rs<br />&nbsp;&nbsp; Set Rs = DB(&quot;Select [Name],[Code] From [{pre}Label]&quot;, 1)<br />&nbsp;&nbsp; If Not Rs.Eof Then<br />&nbsp;&nbsp;&nbsp; Call SetCache(&quot;MyLable&quot;, Rs.Getrows())<br />&nbsp;&nbsp;&nbsp; Call SetCache(&quot;MyLableState&quot;, &quot;Yes&quot;)<br />&nbsp;&nbsp;&nbsp; Rs.Close: Set Rs = Nothing<br />&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp; Rs.Close: Set Rs = Nothing<br />&nbsp;&nbsp;&nbsp; Call SetCache(&quot;MyLableState&quot;, &quot;No&quot;)<br />&nbsp;&nbsp;&nbsp; Content = RegReplace(Content, &quot;{My:([\s\S]*?)}&quot;, &quot;&quot;): Exit Function<br />&nbsp;&nbsp; End If<br />End If<br />Dim Ns, i, j<br />Ns = GetCache(&quot;MyLable&quot;)<br />Dim Matches, Match, MyValue<br />Reg.Pattern = &quot;{My:([\s\S]*?)}&quot;<br />Set Matches = Reg.Execute(Content)<br />For Each Match In Matches<br />&nbsp;&nbsp; If Len(Replace(Match.SubMatches(0), &quot; &quot;, &quot;&quot;)) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp; MyValue = Lang_Parser_My_1 &amp; &quot; &lt;font color=red&gt;&quot; &amp; Replace(Match.SubMatches(0), &quot; &quot;, &quot;&quot;) &amp; &quot;&lt;/font&gt; &quot; &amp; Lang_Parser_My_2<br />&nbsp;&nbsp;&nbsp; For i = 0 To UBound(Ns, 2)<br />&nbsp;&nbsp;&nbsp;&nbsp; If LCase(Ns(0, i)) = LCase(Replace(Match.SubMatches(0), &quot; &quot;, &quot;&quot;)) Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyValue = Ns(1, i)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If InStr(MyValue, &quot;＄＄＄&quot;) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Randomize<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = Round(UBound(Split(MyValue, &quot;＄＄＄&quot;)) * Rnd) '随机值第一个到最后一个<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; MyValue = Split(MyValue, &quot;＄＄＄&quot;)(j)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit For<br />&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp; End If<br />&nbsp;&nbsp; Content = Replace(Content, Match.Value, MyValue) ' 替换<br />&nbsp;&nbsp; If Err Then Err.Clear: Response.Write &quot;&lt;font color=red&gt;&quot; &amp; Lang_Parser_My_Error &amp; &quot;[&quot; &amp; AspArr(i) &amp; &quot;]&lt;/font&gt;&quot;: Response.End<br />Next<br />End Function<br /><br />' 分析系统标签<br />Public Function Parser_Sys()<br />On Error Resume Next<br />Dim Matches, Match, SysValue<br />Reg.Pattern = &quot;{Sys:([\s\S]*?)}&quot;<br />Set Matches = Reg.Execute(Content)<br />For Each Match In Matches<br />&nbsp;&nbsp; If InStr(LCase(Match.SubMatches(0)), &quot;database&quot;) = 0 Then<br />&nbsp;&nbsp;&nbsp; If Len(Replace(Match.SubMatches(0), &quot; &quot;, &quot;&quot;)) &gt; 0 Then Execute (&quot;SysValue = &quot; &amp; Replace(Match.SubMatches(0), &quot; &quot;, &quot;&quot;)) Else SysValue = &quot;&quot;<br />&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp; SysValue = &quot;&quot;<br />&nbsp;&nbsp; End If<br />&nbsp;&nbsp; Content = Replace(Content, Match.Value, SysValue) ' 替换<br />&nbsp;&nbsp; If Err Then Err.Clear: Response.Write &quot;&lt;font color=red&gt;&quot; &amp; Lang_Parser_Sys_Error &amp; &quot;[&quot; &amp; AspArr(i) &amp; &quot;]&lt;/font&gt;&quot;: Response.End<br />Next<br />reg.pattern = &quot;&lt;(.*?)(src=|href=|value=)&quot;&quot;(images/|css/|js/)(.*?)&quot;&quot;(.*?)&gt;&quot;<br />content = reg.replace(content, &quot;&lt;$1$2&quot;&quot;&quot; &amp; httpurl &amp; installdir &amp; templatedir &amp; &quot;/$3$4&quot;&quot;$5&gt;&quot;)<br />reg.pattern = &quot;{tag:goto}&quot;<br />content = reg.replace(content, httpurl &amp; installdir &amp; &quot;redirect.asp?&quot;)<br />End Function<br /><br />' 列表标签<br />'&lt;!--commend:{ $row=10 $cid={field:cid} $mode=commend }--&gt;..............................&lt;!--commend--&gt;<br />Public Function Parser_Com()<br />On Error Resume Next<br />Dim Matches, Match<br />Dim Rs, i, j<br />Dim Matche, BackValue<br />Dim TagLabs, Tagsstr, Loopstr<br />Dim Tag_Cache, Tag_Row, Tag_Col, Tag_Width, Tag_Class<br />Dim Tag_Aid, Tag_Cid, Tag_Type, Tag_Mode, Tag_Keys, Tag_Order<br />Dim Tag_SQL, Tag_Table, Tag_Where, Tag_Field<br />Reg.Pattern = &quot;&lt;!--(.+?):\{(.+?)\}--&gt;([\s\S]*?)&lt;!--\1--&gt;&quot;<br />Set Matches = Reg.Execute(Content)<br />For Each Match In Matches<br />&nbsp;&nbsp; TagLabs = Match.SubMatches(0)&nbsp;&nbsp; ' 标签<br />&nbsp;&nbsp; Tagsstr = Match.SubMatches(1)&nbsp;&nbsp; ' 属性<br />&nbsp;&nbsp; Loopstr = Match.SubMatches(2)&nbsp;&nbsp; ' innerText<br />&nbsp;&nbsp; <br />&nbsp;&nbsp; If LCase(TagLabs) &lt;&gt; &quot;page&quot; Then ' 分页标签<br />&nbsp;&nbsp;&nbsp; ' 共用属性<br />&nbsp;&nbsp;&nbsp; Tag_Cache = GetAttr(Tagsstr, &quot;cache&quot;, True) ' 缓存时间 def:defcachetime<br />&nbsp;&nbsp;&nbsp; Tag_Row = GetAttr(Tagsstr, &quot;row&quot;, True) ' 列数量 def:10<br />&nbsp;&nbsp;&nbsp; Tag_Col = GetAttr(Tagsstr, &quot;col&quot;, True) ' 行数量 def:1<br />&nbsp;&nbsp;&nbsp; Tag_Width = GetAttr(Tagsstr, &quot;width&quot;, True) '#表格宽度<br />&nbsp;&nbsp;&nbsp; Tag_Class = GetAttr(Tagsstr, &quot;class&quot;, False) '#表格样式<br />&nbsp;&nbsp;&nbsp; Tag_Field = GetAttr(Tagsstr, &quot;field&quot;, True) ' 所有字段<br />&nbsp;&nbsp;&nbsp; If Len(Tag_Cache) = 0 Or Not IsNumeric(Tag_Cache) Then Tag_Cache = -1 ' 标签不用缓存<br />&nbsp;&nbsp;&nbsp; If Len(Tag_Row) = 0 Or Not IsNumeric(Tag_Row) Then Tag_Row = 10<br />&nbsp;&nbsp;&nbsp; If Int(Tag_Row) &lt; 1 Then Tag_Row = 1<br />&nbsp;&nbsp;&nbsp; If Len(Tag_Col) = 0 Or Not IsNumeric(Tag_Col) Then Tag_Col = 1<br />&nbsp;&nbsp;&nbsp; If Int(Tag_Col) &lt; 1 Then Tag_Col = 1<br />&nbsp;&nbsp;&nbsp; If Len(Tag_Width) = 0 Then Tag_Width = &quot;100%&quot;<br />&nbsp;&nbsp;&nbsp; If Len(Tag_Class) &gt; 0 Then Tag_Class = &quot; Class=&quot;&quot;&quot; &amp; Tag_Class &amp; &quot;&quot;&quot; &quot;<br />&nbsp;&nbsp;&nbsp; If Len(Tag_Field) = 0 Then Tag_Field = &quot;*&quot;<br />&nbsp;&nbsp;&nbsp; Tag_Cache = Int(Tag_Cache): Tag_Row = Int(Tag_Row): Tag_Col = Int(Tag_Col)<br />&nbsp;&nbsp;&nbsp; ' 内容Content专用属性<br />&nbsp;&nbsp;&nbsp; Tag_Aid = GetAttr(Tagsstr, &quot;aid&quot;, True) ' 这个文章不显示出来<br />&nbsp;&nbsp;&nbsp; Tag_Cid = GetAttr(Tagsstr, &quot;cid&quot;, True) ' 栏目ID,多用个,号分隔<br />&nbsp;&nbsp;&nbsp; Tag_Type = GetAttr(Tagsstr, &quot;type&quot;, True)&nbsp;&nbsp; ' 类型: text/images def:text<br />&nbsp;&nbsp;&nbsp; Tag_Mode = GetAttr(Tagsstr, &quot;mode&quot;, True)&nbsp;&nbsp; ' 类型(推荐,热门,相关)<br />&nbsp;&nbsp;&nbsp; Tag_Keys = GetAttr(Tagsstr, &quot;keys&quot;, True)&nbsp;&nbsp; ' 关键字<br />&nbsp;&nbsp;&nbsp; Tag_Order = GetAttr(Tagsstr, &quot;order&quot;, False) ' 排序 def:[id] desc[组合查询可用]<br />&nbsp;&nbsp;&nbsp; Tag_SQL = GetAttr(Tagsstr, &quot;sql&quot;, False) ' 单独SQL查询<br />&nbsp;&nbsp;&nbsp; Tag_Table = GetAttr(Tagsstr, &quot;table&quot;, True) ' 组合查询,表<br />&nbsp;&nbsp;&nbsp; Tag_Where = GetAttr(Tagsstr, &quot;where&quot;, False) ' 组合查询,条件<br />&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; ' 默认设置<br />&nbsp;&nbsp;&nbsp; If LCase(Tag_Table) = &quot;channel&quot; And Len(Tag_Where) = 0 Then Tag_Where = &quot;[FatherID]=0 And [OutSideLink]=0 And [Order]&gt;=0&quot;<br />&nbsp;&nbsp;&nbsp; If LCase(Tag_Table) = &quot;channel&quot; And Len(Tag_Order) = 0 Then Tag_Order = &quot;[Order] Desc,[ID] Desc&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />&nbsp;&nbsp;&nbsp; ' SQL查询组合<br />&nbsp;&nbsp;&nbsp; If Len(Tag_SQL) = 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Table) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Where) &gt; 0 Then Tag_Where = &quot; Where &quot; &amp; Tag_Where &amp; &quot; &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Order) = 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LCase(Tag_Table) = &quot;channel&quot; Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_Order = &quot;[Order] Desc,[ID] Desc&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_Order = &quot;[ID] Desc&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_SQL = &quot;Select Top &quot; &amp; Tag_Row * Tag_Col &amp; &quot; &quot; &amp; Tag_Field &amp; &quot; From [{pre}&quot; &amp; Tag_Table &amp; &quot;] &quot; &amp; Tag_Where &amp; &quot; Order By &quot; &amp; Tag_Order ' 最终查询语句<br />&nbsp;&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_Where = &quot;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Aid) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tag_Aid, &quot;,&quot;) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_Where = &quot; [ID] In (&quot; &amp; Tag_Aid &amp; &quot;) &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_Where = &quot; [ID]&lt;&gt;&quot; &amp; Tag_Aid &amp; &quot; &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Cid) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Where) &gt; 0 Then Tag_Where = Tag_Where &amp; &quot; And [Cid] In (&quot; &amp; Tag_Cid &amp; &quot;) &quot; Else Tag_Where = &quot; [Cid] In (&quot; &amp; Tag_Cid &amp; &quot;) &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'If Len(Tag_Where) &gt; 0 Then Tag_Where = Tag_Where &amp; &quot; And ([Cid] In (&quot; &amp; Tag_Cid &amp; &quot;) or [Sid] in (&quot; &amp; tag_cid &amp; &quot;)) &quot; Else Tag_Where = &quot; ([Cid] In (&quot; &amp; Tag_Cid &amp; &quot;) or [Sid] in (&quot; &amp; tag_cid &amp; &quot;)) &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LCase(Tag_Type) = &quot;images&quot; Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Where) &gt; 0 Then Tag_Where = Tag_Where &amp; &quot; And [Indexpic]&lt;&gt;'' &quot; Else Tag_Where = Tag_Where &amp; &quot; [Indexpic]&lt;&gt;'' &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LCase(Tag_Type) = &quot;noimages&quot; Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Where) &gt; 0 Then Tag_Where = Tag_Where &amp; &quot; And [Indexpic]='' &quot; Else Tag_Where = Tag_Where &amp; &quot; [Indexpic]='' &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Select Case LCase(Tag_Mode)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;commend&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Where) &gt; 0 Then Tag_Where = Tag_Where &amp; &quot; And [Commend]=1 &quot; Else Tag_Where = Tag_Where &amp; &quot; [Commend]=1 &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;uncommend&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Where) &gt; 0 Then Tag_Where = Tag_Where &amp; &quot; And [Commend]=0 &quot; Else Tag_Where = Tag_Where &amp; &quot; [Commend]=0 &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;about&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Keys) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_Cache = -1 ' 不缓存<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Dim Tag_KeysLink<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_Keys = Split(Replace(Tag_Keys, &quot;'&quot;, &quot;&quot;), &quot;,&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = UBound(Tag_Keys): If j &gt; 5 Then j = 5<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 0 To j<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Keys(i)) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_KeysLink) = 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_KeysLink = &quot; [Keywords] Like '%&quot; &amp; Tag_Keys(i) &amp; &quot;%'&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_KeysLink = Tag_KeysLink &amp; &quot; Or [Keywords] Like '%&quot; &amp; Tag_Keys(i) &amp; &quot;%'&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_KeysLink) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Where) &gt; 0 Then Tag_Where = Tag_Where &amp; &quot; And (&quot; &amp; Tag_KeysLink &amp; &quot;) &quot; Else Tag_Where = Tag_Where &amp; &quot; (&quot; &amp; Tag_KeysLink &amp; &quot;) &quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End Select<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If LCase(Tag_Mode) = &quot;hot&quot; Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_Order = &quot;[Views] Desc&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Order) = 0 Then Tag_Order = &quot;[ID] Desc&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tag_Where) &gt; 0 Then Tag_Where = Tag_Where &amp; &quot; And [Display]=1 &quot; Else Tag_Where = &quot; [Display]=1&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tag_SQL = &quot;Select Top &quot; &amp; Tag_Row * Tag_Col &amp; &quot; &quot; &amp; Tag_Field &amp; &quot; From [{pre}Content] Where &quot; &amp; Tag_Where &amp; &quot; Order By &quot; &amp; Tag_Order ' 最终查询语句<br />&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp; Cachetimei = Tag_Cache ' 标签缓存<br />&nbsp;&nbsp;&nbsp; If ChkCacheSQL(Template &amp; Tag_SQL) Then<br />&nbsp;&nbsp;&nbsp;&nbsp; BackValue = GetCache(Template &amp; Tag_SQL)<br />&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp; BackValue = &quot;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp; Err.Clear<br />&nbsp;&nbsp;&nbsp;&nbsp; Set Rs = DB(Tag_SQL, 3)<br />&nbsp;&nbsp;&nbsp;&nbsp; If Err Then Response.Write &quot;&lt;font color=red&gt;&quot; &amp; Lang_Parser_Com_Error &amp; &quot;[&quot; &amp; Tag_SQL &amp; &quot; =&gt; &amp; &quot; &amp; Err.Description &amp; &quot;]&lt;/font&gt;&quot;: Response.End<br />&nbsp;&nbsp;&nbsp;&nbsp; If Tag_Col &gt; 1 Then BackValue = BackValue &amp; &quot;&lt;table width=&quot;&quot;&quot; &amp; Tag_Width &amp; &quot;&quot;&quot; &quot; &amp; Tag_Class &amp; &quot; border=&quot;&quot;0&quot;&quot; cellpadding=&quot;&quot;0&quot;&quot; cellspacing=&quot;&quot;0&quot;&quot;&gt;&quot; &amp; vbCrLf: j = 0 ' 表<br />&nbsp;&nbsp;&nbsp;&nbsp; Session(Cacheflag &amp; &quot;_Parser_i&quot;) = 0<br />&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To Tag_Row * Tag_Col<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Rs.Eof Then Exit For ' 不存在记录就退出<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; j = j + 1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Tag_Col &gt; 1 Then ' 表<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If j = 1 Then BackValue = BackValue &amp; &quot; &lt;tr&gt;&quot; &amp; vbCrLf<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BackValue = BackValue &amp; &quot; &lt;td valign=&quot;&quot;top&quot;&quot; width=&quot;&quot;&quot; &amp; Round(100 / Tag_Col) &amp; &quot;%&quot;&quot;&gt;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(TagLabs) = 0 Then TagLabs = &quot;field&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session(Cacheflag &amp; &quot;_Parser_i&quot;) = Session(Cacheflag &amp; &quot;_Parser_i&quot;) + 1 ' 记数<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BackValue = BackValue &amp; Parser_Tags(&quot;\[&quot; &amp; TagLabs &amp; &quot;:(.+?)\]&quot;, Loopstr, Rs) ' 替换<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Tag_Col &gt; 1 Then ' 表<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BackValue = BackValue &amp; &quot; &lt;/td&gt;&quot; &amp; vbCrLf<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If j = Tag_Col Then BackValue = BackValue &amp; &quot; &lt;/tr&gt;&quot; &amp; vbCrLf: j = 0<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Rs.MoveNext<br />&nbsp;&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp;&nbsp;&nbsp; If Tag_Col &gt; 1 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If j &lt; Tag_Col And j &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To Tag_Col - j<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BackValue = BackValue &amp; &quot; &lt;td&gt;&lt;/td&gt;&quot; &amp; vbCrLf<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BackValue = BackValue &amp; &quot; &lt;/tr&gt;&quot; &amp; vbCrLf<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; BackValue = BackValue &amp; &quot;&lt;/table&gt;&quot; &amp; vbCrLf<br />&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp;&nbsp; Rs.Close<br />&nbsp;&nbsp;&nbsp;&nbsp; Call SetCache(Template &amp; Tag_SQL, BackValue)<br />&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp; Content = Replace(Content, Match.Value, BackValue)<br />&nbsp;&nbsp; End If<br />Next<br />If RegExists(&quot;&lt;!--(.+?):\{(.+?)\}--&gt;([\s\S]*?)&lt;!--\1--&gt;&quot;, Content) Then Call Parser_Com ' 多次调用<br />End Function<br /><br />' 分页标签<br />Public Function Parser_Page()<br />'On Error Resume Next<br />Dim Matches, Match<br />Dim Rs, i, j<br />Dim Matche, BackValue<br />Dim Tagsstr, Loopstr<br />Dim Tag_Size, Tag_Order, Tag_Field, Tag_Table, Tag_Style, Tag_SQL, Tag_Where<br />Dim Tag_RecordCount, Tag_PageCount<br />Reg.Pattern = &quot;&lt;!--Page:\{(.+?)\}--&gt;([\s\S]*?)&lt;!--Page--&gt;&quot;<br />Set Matches = Reg.Execute(Content)<br />For Each Match In Matches<br />&nbsp;&nbsp; BackValue = &quot;&quot;<br />&nbsp;&nbsp; Tagsstr = Match.SubMatches(0)&nbsp;&nbsp; ' 属性<br />&nbsp;&nbsp; Loopstr = Match.SubMatches(1)&nbsp;&nbsp; ' innerText<br />&nbsp;&nbsp; Tag_Size = GetAttr(Tagsstr, &quot;size&quot;, True)<br />&nbsp;&nbsp; Tag_Order = GetAttr(Tagsstr, &quot;order&quot;, False)<br />&nbsp;&nbsp; Tag_Table = GetAttr(Tagsstr, &quot;table&quot;, True)<br />&nbsp;&nbsp; Tag_Style = GetAttr(Tagsstr, &quot;style&quot;, True)<br />&nbsp;&nbsp; Tag_Field = GetAttr(Tagsstr, &quot;field&quot;, True) ' 所有字段<br />&nbsp;&nbsp; If Len(Tag_Size) = 0 Or Not IsNumeric(Tag_Size) Then Tag_Size = 10<br />&nbsp;&nbsp; If Len(Tag_Order) = 0 Then Tag_Order = &quot;[ID] Desc&quot;<br />&nbsp;&nbsp; If Len(Tag_Table) = 0 Then Tag_Table = &quot;Content&quot;<br />&nbsp;&nbsp; If Len(Tag_Style) = 0 Or Not IsNumeric(Tag_Style) Then Tag_Style = 1<br />&nbsp;&nbsp; If Len(Tag_Field) = 0 Then Tag_Field = &quot;*&quot;<br />&nbsp;&nbsp; Tag_Size = Int(Tag_Size): Tag_Table = &quot; [{pre}&quot; &amp; Tag_Table &amp; &quot;] &quot;: Tag_Style = Int(Tag_Style): Tag_Where = &quot; [Display]=1 &quot;</p>
<p>&nbsp;&nbsp; If Len(CID) &gt; 0 And isnumeric(CID) Then Tag_Where = Tag_Where &amp; &quot; And [CID]=&quot; &amp; CID ' 存在CID则调用指定CID/SID的内容<br />&nbsp;&nbsp; 'If Len(CID) &gt; 0 And isnumeric(CID) Then Tag_Where = Tag_Where &amp; &quot; And ([CID]=&quot; &amp; CID &amp; &quot; Or [SID]=&quot; &amp; CID &amp; &quot;)&quot; ' 存在CID则调用指定CID/SID的内容<br />&nbsp;&nbsp; If Len(CID) = 0 And Len(SID)&gt;0 And isnumeric(SID) Then Tag_Where = Tag_Where &amp; &quot; And [SID]=&quot; &amp; SID ' 不存在CID,而存在SID则调用SID的内容</p>
<p>&nbsp;&nbsp; Set Rs = New DataList<br />&nbsp;&nbsp; Rs.Result = 1<br />&nbsp;&nbsp; Rs.Field = Tag_Field<br />&nbsp;&nbsp; Rs.Table = Tag_Table<br />&nbsp;&nbsp; Rs.Where = Tag_Where<br />&nbsp;&nbsp; Rs.Order = Tag_Order<br />&nbsp;&nbsp; Rs.PageSize = Tag_Size<br />&nbsp;&nbsp; Rs.AbsolutePage = Page<br />&nbsp;&nbsp; Rs.List()<br />&nbsp;&nbsp; Session(Cacheflag &amp; &quot;_Parser_i&quot;) = 0<br />&nbsp;&nbsp; For i = 1 To Tag_Size<br />&nbsp;&nbsp;&nbsp; If Rs.Data.Eof Then Exit For<br />&nbsp;&nbsp;&nbsp; Session(Cacheflag &amp; &quot;_Parser_i&quot;) = Session(Cacheflag &amp; &quot;_Parser_i&quot;) + 1 ' 记数<br />&nbsp;&nbsp;&nbsp; BackValue = BackValue &amp; Parser_Tags(&quot;\[Page:(.+?)\]&quot;, Loopstr, Rs.Data) ' 替换<br />&nbsp;&nbsp;&nbsp; Rs.Data.MoveNext<br />&nbsp;&nbsp; Next<br />&nbsp;&nbsp; Content = RegReplace(Content, &quot;{tag:page}&quot;, &quot;{{tag:page_www.5u.hk}}&quot;)<br />&nbsp;&nbsp; Content = Replace(Content, Match.Value, BackValue)<br />&nbsp;&nbsp; Tag_RecordCount = Rs.RecordCount: Tag_PageCount = Rs.PageCount: Rs.Data.Close<br />&nbsp;&nbsp; If Tag_PageCount = 0 Then Tag_PageCount = 1<br />Next<br />Dim GetPageList<br />if matches.count &gt;0 then<br />&nbsp;&nbsp; GetPageList = PageListX(Tag_PageCount, Tag_RecordCount, Page, Tag_Size, CID)<br />end if<br />Content = RegReplace(Content, &quot;{{tag:page_www.5u.hk}}&quot;, GetPageList)<br />Set Rs = Nothing<br />End Function<br /><br />' 字符替换<br />Public Function Parser_Tags(ByVal Pattern, ByVal Temp, ByVal Dat)<br />On Error Resume Next<br />Dim Matches, Match<br />Dim Tagsstr, Tagsval, Tagsvalt, TagTitle: TagTitle = False<br />Dim Tag_Len, Tag_Lenext, Tag_Format, Tag_Replace, Tag_Function,Tag_width,Tag_Height<br />Dim Re, Re1, Re2<br />Dim i, c, l, t<br />Reg.Pattern = Pattern<br />Set Matches = Reg.Execute(Temp)<br />For Each Match In Matches<br />&nbsp;&nbsp; Tagsstr = Match.SubMatches(0)<br />&nbsp;&nbsp; Tag_Len = GetAttr(Tagsstr, &quot;len&quot;, True)<br />&nbsp;&nbsp; Tag_Lenext = GetAttr(Tagsstr, &quot;lenext&quot;, True)<br />&nbsp;&nbsp; Tag_Format = GetAttr(Tagsstr, &quot;format&quot;, False)<br />&nbsp;&nbsp; Tag_Replace = GetAttr(Tagsstr, &quot;replace&quot;, False)<br />&nbsp;&nbsp; Tag_Function = GetAttr(Tagsstr, &quot;function&quot;, True)<br />&nbsp;&nbsp; Tag_Width=GetAttr(Tagsstr, &quot;width&quot;, True)<br />&nbsp;&nbsp; Tag_Height=GetAttr(Tagsstr, &quot;height&quot;, True)<br />&nbsp;&nbsp; Tagsval = Split(Tagsstr, &quot; &quot;)(0)<br />&nbsp;&nbsp; Select Case LCase(Tagsval)<br />&nbsp;&nbsp; Case &quot;aid&quot;<br />&nbsp;&nbsp;&nbsp; Tagsval = Dat(&quot;AID&quot;)<br />&nbsp;&nbsp;&nbsp; If Err Then Err.Clear: Tagsval = Dat(&quot;ID&quot;)&nbsp;&nbsp;&nbsp; ' Content<br />&nbsp;&nbsp; Case &quot;aurl&quot;<br />&nbsp;&nbsp;&nbsp; Tagsval = Dat(&quot;ID&quot;) ' Content<br />&nbsp;&nbsp;&nbsp; Tagsval = BuildViewPath(Dat(&quot;ID&quot;), Dat(&quot;Cid&quot;), Dat(&quot;Diyname&quot;), Dat(&quot;Createtime&quot;), Dat(&quot;ViewPath&quot;))<br />&nbsp;&nbsp; Case &quot;curl&quot;<br />&nbsp;&nbsp;&nbsp; Tagsval = Dat(&quot;Cid&quot;) ' Content<br />&nbsp;&nbsp;&nbsp; If Err Then Err.Clear: Tagsval = Dat(&quot;ID&quot;) ' Channel<br />&nbsp;&nbsp;&nbsp; If Createhtml = 1 Then ' 栏目只在1时才会生成,其他均不生成<br />&nbsp;&nbsp;&nbsp;&nbsp; If Len(GetChannel(Tagsval, &quot;Domain&quot;)) &gt; 0 Then Tagsval = GetChannel(Tagsval, &quot;Domain&quot;) Else Tagsval = Httpurl &amp; GetChannel(Tagsval, &quot;Ruleindex&quot;)<br />&nbsp;&nbsp;&nbsp; Else ' ASP<br />&nbsp;&nbsp;&nbsp;&nbsp; If Len(GetChannel(Tagsval, &quot;Domain&quot;)) &gt; 0 Then Tagsval = GetChannel(Tagsval, &quot;Domain&quot;) Else Tagsval = Httpurl &amp; Installdir &amp; &quot;channel.asp?id=&quot; &amp; Tagsval<br />&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp; Case &quot;surl&quot; ' sid -&gt; name<br />&nbsp;&nbsp;&nbsp; Tagsval = &quot;&quot;<br />&nbsp;&nbsp; Case &quot;cname&quot;<br />&nbsp;&nbsp;&nbsp; Tagsval = GetChannel(Dat(&quot;cid&quot;), &quot;name&quot;)<br />&nbsp;&nbsp; Case &quot;sname&quot; ' sid -&gt; name<br />&nbsp;&nbsp;&nbsp; Tagsval = &quot;&quot;<br />&nbsp;&nbsp; Case &quot;ctable&quot;<br />&nbsp;&nbsp;&nbsp; Tagsval = GetChannel(Dat(&quot;cid&quot;), &quot;table&quot;)<br />&nbsp;&nbsp; Case &quot;titlex&quot;<br />&nbsp;&nbsp;&nbsp; Tagsval = Dat(&quot;Title&quot;) ' Content<br />&nbsp;&nbsp;&nbsp; TagTitle = True<br />&nbsp;&nbsp; Case &quot;modeindex&quot;<br />&nbsp;&nbsp;&nbsp; Tagsval = &quot;&quot;<br />&nbsp;&nbsp; Case &quot;i&quot;<br />&nbsp;&nbsp;&nbsp; Tagsval = Session(Cacheflag &amp; &quot;_Parser_i&quot;)<br />&nbsp;&nbsp; Case Else<br />&nbsp;&nbsp;&nbsp; If LCase(Left(Tagsval, 5)) = &quot;mode_&quot; Then<br />&nbsp;&nbsp;&nbsp;&nbsp; Dim Modetag: Modetag = Right(Tagsval, Len(Tagsval) - 5)<br />&nbsp;&nbsp;&nbsp;&nbsp; Tagsval = Dat(&quot;ModeIndex&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tagsval) &gt; 0 And InStr(Tagsval, &quot;&lt;&quot; &amp; Modetag &amp; &quot;&gt;&quot;) &gt; 0 And InStr(Tagsval, &quot;&lt;/&quot; &amp; Modetag &amp; &quot;&gt;&quot;) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ' Get Mode Tag Value<br />&nbsp;&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tagsval = &quot;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp;&nbsp; Else<br />&nbsp;&nbsp;&nbsp;&nbsp; Tagsval = Dat(Tagsval)<br />&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp; End Select<br />&nbsp;&nbsp; Tagsval = Replace(Replace(Replace(Replace(Tagsval, &quot;&amp;nbsp;&quot;, &quot; &quot;), &quot;&amp;quot;&quot;, Chr(34)), &quot;&amp;gt;&quot;, &quot;&gt;&quot;), &quot;&amp;lt;&quot;, &quot;&lt;&quot;)<br />&nbsp;&nbsp; If Len(Replace(Tag_Replace, &quot; &quot;, &quot;&quot;)) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp; Re = Split(Tag_Replace, &quot;##&quot;)<br />&nbsp;&nbsp;&nbsp; If UBound(Re) &gt;= 0 Then Re1 = Re(0): Re2 = Re(1) Else Re1 = Re(0): Re2 = Re(0)<br />&nbsp;&nbsp;&nbsp; Tagsval = Replace(Tagsval, Re1, Re2)<br />&nbsp;&nbsp; End If<br />&nbsp;&nbsp; If Len(Replace(Tag_Format, &quot; &quot;, &quot;&quot;)) &gt; 0 Then ' 格式化时间<br />&nbsp;&nbsp;&nbsp; If IsDate(Tagsval) Then<br />&nbsp;&nbsp;&nbsp;&nbsp; Tagsvalt = Tagsval: Tagsvalt = LCase(Tag_Format): Tagsvalt = Replace(Tagsvalt, &quot;weeka&quot;, &quot;WEEKA&quot;): Tagsvalt = Replace(Tagsvalt, &quot;montha&quot;, &quot;MONTHA&quot;): Tagsvalt = Replace(Tagsvalt, &quot;week&quot;, &quot;WEEK&quot;): Tagsvalt = Replace(Tagsvalt, &quot;month&quot;, &quot;MONTH&quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;WEEKA&quot;) Then Tagsvalt = Replace(Tagsvalt, &quot;WEEKA&quot;, Lang_Week_Abbr(Weekday(Tagsval)))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;WEEK&quot;) Then Tagsvalt = Replace(Tagsvalt, &quot;WEEK&quot;, Lang_Week(Weekday(Tagsval)))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;MONTHA&quot;) Then Tagsvalt = Replace(Tagsvalt, &quot;MONTHA&quot;, Lang_Month_Abbr(Month(Tagsval)))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;MONTH&quot;) Then Tagsvalt = Replace(Tagsvalt, &quot;MONTH&quot;, Lang_Month(Month(Tagsval)))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;yyyy&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;yyyy&quot;, Year(Tagsval))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;yy&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;yy&quot;, Right(Year(Tagsval), 2))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;mm&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;mm&quot;, Right(&quot;0&quot; &amp; Month(Tagsval), 2))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;m&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;m&quot;, Month(Tagsval))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;dd&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;dd&quot;, Right(&quot;0&quot; &amp; Day(Tagsval), 2))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;d&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;d&quot;, Day(Tagsval))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;hh&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;hh&quot;, Right(&quot;0&quot; &amp; Hour(Tagsval), 2))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;h&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;h&quot;, Hour(Tagsval))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;nn&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;nn&quot;, Right(&quot;0&quot; &amp; Minute(Tagsval), 2))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;n&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;n&quot;, Minute(Tagsval))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;ss&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;ss&quot;, Right(&quot;0&quot; &amp; Second(Tagsval), 2))<br />&nbsp;&nbsp;&nbsp;&nbsp; If InStr(Tagsvalt, &quot;s&quot;) &gt; 0 Then Tagsvalt = Replace(Tagsvalt, &quot;s&quot;, Second(Tagsval))<br />&nbsp;&nbsp;&nbsp;&nbsp; Tagsval = Tagsvalt<br />&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp; End If<br />&nbsp;&nbsp; If Len(Tag_Len) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp; If IsNumeric(Tag_Len) Then<br />&nbsp;&nbsp;&nbsp;&nbsp; Tag_Len = Int(Tag_Len)<br />&nbsp;&nbsp;&nbsp;&nbsp; For i = 1 To Len(Tagsval)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; c = Abs(Asc(Mid(Tagsval, i, 1)))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If c &gt; 255 Or c &lt; 2 Then t = t + 2 Else t = t + 1<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If t &gt;= Tag_Len Then Tagsval = Left(Tagsval, i) &amp; Tag_Lenext: Exit For<br />&nbsp;&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp;&nbsp; End If<br />&nbsp;&nbsp; End If<br />&nbsp;&nbsp; If Len(Tag_Function) &gt; 0 Then<br />&nbsp;&nbsp;&nbsp; Tag_Function = Split(Tag_Function, &quot;,&quot;)<br />&nbsp;&nbsp;&nbsp; For i = 0 To UBound(Tag_Function)<br />&nbsp;&nbsp;&nbsp;&nbsp; Select Case LCase(Tag_Function(i))<br />&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;urlencode&quot;: Tagsval = Server.UrlEnCode(Tagsval)<br />&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;htmlencode&quot;: Tagsval = Server.HtmlEnCode(Tagsval)<br />&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;abs&quot;: Tagsval = Abs(Tagsval)<br />&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;trim&quot;: Tagsval = Trim(Tagsval)<br />&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;ucase&quot;: Tagsval = UCase(Tagsval)<br />&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;lcase&quot;: Tagsval = LCase(Tagsval)<br />&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;clearhtml&quot;: Tagsval = RegReplace(Tagsval, &quot;(\&lt;.+?\&gt;)&quot;, &quot;&quot;): Tagsval = Replace(Trim(Tagsval), vbCrLf, &quot; &quot;)<br />&nbsp;&nbsp;&nbsp;&nbsp; Case &quot;tags&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; t = Split(Tagsval, &quot;,&quot;): Tagsval = &quot;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; For c = 0 To UBound(t)<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If Len(Tagsval) &gt; 0 Then Tagsval = Tagsval &amp; &quot;,&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Tagsval = Tagsval &amp; &quot; &lt;a href='&quot; &amp; Httpurl &amp; Installdir &amp; &quot;plus/search/index.asp?keyword=&quot; &amp; Server.UrlEnCode(t(c)) &amp; &quot;'&gt;&quot; &amp; t(c) &amp; &quot;&lt;/a&gt;&quot;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp;&nbsp;&nbsp; End Select<br />&nbsp;&nbsp;&nbsp; Next<br />&nbsp;&nbsp; End If<br />&nbsp;&nbsp; If len(Tag_Width) &gt; 0 or len(Tag_Height) &gt; 0 then<br />&nbsp;&nbsp;&nbsp; If instr(tag_width,&quot;,&quot;) &gt; 0 or len(tag_width)=0 then tag_width = 100 else tag_width = int(tag_width)<br />&nbsp;&nbsp;&nbsp; If instr(tag_height,&quot;,&quot;) &gt; 0 or len(tag_height)=0 then tag_height = 100 else tag_height = int(tag_height)<br />&nbsp;&nbsp;&nbsp; Tagsval = Cutjpeg(Tagsval,Tag_Width , tag_height)<br />&nbsp;&nbsp; end if<br />&nbsp;&nbsp; If IsNull(Tagsval) Then Tagsval = &quot;&quot;<br />&nbsp;&nbsp; If TagTitle Then<br />&nbsp;&nbsp;&nbsp; TagTitle = False<br />&nbsp;&nbsp;&nbsp; Dim TitleStyle: TitleStyle = Split(Dat(&quot;Style&quot;) &amp; &quot;,&quot;, &quot;,&quot;)<br />&nbsp;&nbsp;&nbsp; If Len(TitleStyle(0)) &gt; 0 Then Tagsval = &quot;&lt;&quot; &amp; TitleStyle(0) &amp; &quot;&gt;&quot; &amp; Tagsval &amp; &quot;&lt;/&quot; &amp; TitleStyle(0) &amp; &quot;&gt;&quot;<br />&nbsp;&nbsp;&nbsp; If Len(TitleStyle(1)) &gt; 0 Then Tagsval = &quot;&lt;font color=&quot;&quot;&quot; &amp; TitleStyle(1) &amp; &quot;&quot;&quot;&gt;&quot; &amp; Tagsval &amp; &quot;&lt;/font&gt;&quot;<br />&nbsp;&nbsp; End If<br />&nbsp;&nbsp; Temp = Replace(Temp, Match.Value, Tagsval)<br />Next<br />Parser_Tags = Temp<br />End Function<br /><br />' 判断标签<br />Public Function Parser_IF()<br />On Error Resume Next<br />Dim Matches, Match<br />Dim TestIF<br />Reg.Pattern = &quot;{If:(.+?)}([\s\S]*?){Else}([\s\S]*?){End If}&quot;<br />Set Matches = Reg.Execute(Content)<br />For Each Match In Matches<br />&nbsp;&nbsp; Execute (&quot;If &quot; &amp; Match.SubMatches(0) &amp; &quot; Then TestIf = True Else TestIf = False&quot;)<br />&nbsp;&nbsp; If TestIF Then Content = Replace(Content, Match.Value, Match.SubMatches(1)) Else Content = Replace(Content, Match.Value, Match.SubMatches(2)) ' 替换<br />&nbsp;&nbsp; If Err Then Response.Write &quot;&lt;font color=red&gt;&quot; &amp; Lang_Parser_IF_Error &amp; &quot;[&quot; &amp; Match.SubMatches(0) &amp; &quot;]&quot; &amp; Err.Description &amp; &quot;&lt;/font&gt;&quot;: Err.Clear: Response.End<br />Next<br />Reg.Pattern = &quot;{If:(.+?)}([\s\S]*?){End If}&quot;<br />Set Matches = Reg.Execute(Content)<br />For Each Match In Matches<br />&nbsp;&nbsp; Execute (&quot;If &quot; &amp; Match.SubMatches(0) &amp; &quot; Then TestIf = True Else TestIf = False&quot;)<br />&nbsp;&nbsp; If TestIF Then Content = Replace(Content, Match.Value, Match.SubMatches(1)) Else Content = Replace(Content, Match.Value, &quot;&quot;) ' 替换<br />&nbsp;&nbsp; If Err Then Response.Write &quot;&lt;font color=red&gt;&quot; &amp; Lang_Parser_IF_Error &amp; &quot;[&quot; &amp; Match.SubMatches(0) &amp; &quot;]&quot; &amp; Err.Description &amp; &quot;&lt;/font&gt;&quot;: Err.Clear: Response.End<br />Next<br />End Function<br /><br />' 正表达式替换<br />Public Function RegReplace(ByVal ReplaceContent, ByVal Pattern, ByVal ReplaceVal)<br />Reg.Pattern = Pattern<br />RegReplace = Reg.Replace(ReplaceContent, ReplaceVal)<br />End Function<br /><br />' 是否存在此类标签<br />Public Function RegExists(ByVal Pattern, ByVal TestContent)<br />Reg.Pattern = Pattern<br />RegExists = Reg.Test(TestContent)<br />End Function<br /><br />' 获取指定标签属性的值<br />'Tag_Cache = GetAttr(&quot; $row=10 $cid={field:cid} $mode=commend &quot;, &quot;cache&quot;, True)<br />Public Function GetAttr(ByVal Tagsstr, ByVal AttrName, ByVal ReplaceSpace)<br />If Len(Tagsstr) &lt;= 3 Or InStr(LCase(Tagsstr), &quot;$&quot; &amp; LCase(AttrName) &amp; &quot;=&quot;) = 0 Then GetAttr = &quot;&quot;: Exit Function<br />Dim Matches, Match<br />Reg.Pattern = &quot;\$&quot; &amp; AttrName &amp; &quot;=(.+?) \$&quot;<br />Set Matches = Reg.Execute(Tagsstr &amp; &quot; $&quot;)<br />For Each Match In Matches<br />&nbsp;&nbsp; GetAttr = Match.SubMatches(0)<br />Next<br />If ReplaceSpace Then<br />&nbsp;&nbsp; GetAttr = Replace(GetAttr, &quot; &quot;, &quot;&quot;)<br />&nbsp;&nbsp; If Len(GetAttr) &gt; 0 And IsNumeric(GetAttr) And InStr(GetAttr, &quot;,&quot;) = 0 Then GetAttr = Int(GetAttr)<br />End If<br />End Function</p>
<p>' 载入模板<br />Public Function Loadfile()<br />Dim Obj<br />On Error Resume Next<br />Set Obj = Server.CreateObject(&quot;adodb.stream&quot;)<br />With Obj<br />.Type = 2: .Mode = 3: .Open: .Charset = Response.charset : .Position = Obj.Size: .Loadfromfile Server.Mappath(Template): Content = .ReadText: .Close<br />End With<br />Set Obj = Nothing<br />If Err Then Response.Write &quot;&lt;font color=red&gt;&quot; &amp; Lang_Parser_LoadFile_Error &amp; &quot;[&quot; &amp; Template &amp; &quot;]&lt;/font&gt;&quot;: Response.End<br />End Function<br /><br />public function rep(s,d)<br />content = replace(content,s,d)<br />end function<br /><br /><br />End Class</p>
<p>&nbsp;</p>
<p>%&gt;</p>]]></summary>
	  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/myBlog.asp?s=397" /> 
	  <id>http://www.9702.com.cn/myBlog.asp?a=397</id>
  </entry>	
		
  <entry>
	  <title type="html"><![CDATA[Asp模板替换 自定义标签,生成静态文件/缓存类]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=396" label="Asp模板替换 自定义标签,生成静态文件/缓存类" /> 
	  <updated>2008-11-2 16:48:28</updated>
	  <published>2008-11-2 16:48:28</published>
		  <summary type="html"><![CDATA[<p>text = &quot;&lt;div id=&quot;&quot;id&quot;&quot;&gt;{{id}}&lt;/div&gt; &lt;div id=&quot;&quot;title&quot;&quot;&gt;{{title}}&lt;/div&gt;&quot;<br />a = &quot;&lt;tag:Article id=&quot;&quot;300&quot;&quot; content=&quot;&quot;1500&quot;&quot; /&gt; &lt;tag:loop channelid=&quot;&quot;17&quot;&quot; pagesize=&quot;&quot;10&quot;&quot; title=&quot;&quot;10&quot;&quot; elite=&quot;&quot;fales&quot;&quot; column=&quot;&quot;2&quot;&quot; /&gt;&quot;<br />response.write ProcessCustomTags(a)</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>Function ProcessCustomTags(ByVal sContent)<br />Dim objRegEx, Match, Matches<br />Set objRegEx = New RegExp<br />objRegEx.Pattern = &quot;&lt;tag:[^&lt;&gt;]+?\/&gt;&quot;<br />objRegEx.IgnoreCase = True<br />objRegEx.Global = True<br />Set Matches = objRegEx.Execute(sContent)<br />For Each Match in Matches<br />sContent = Replace(sContent, Match.Value, ParseTag(Match.Value))<br />Next<br />set Matches = nothing<br />set objRegEx = nothing<br />ProcessCustomTags = sContent<br />End Function</p>
<p>function ParseTag(ByVal strTag)<br />dim arrResult, ClassName, arrAttributes, sTemp, i, objClass<br />if len(strTag) = 0 then exit function<br />arrResult = Split(strTag, &quot;:&quot;)<br />ClassName = Split(arrResult(1), &quot; &quot;)(0)<br />select case uCase(ClassName)<br />case &quot;LOOP&quot;<br />'response.write GetAttribute(&quot;channelid&quot;, strTag) &amp; &quot;&lt;br&gt;&quot;<br />'response.write GetAttribute(&quot;pagesize&quot;, strTag) &amp; &quot;&lt;br&gt;&quot;<br />'response.write GetAttribute(&quot;title&quot;, strTag) &amp; &quot;&lt;br&gt;&quot;<br />'response.write GetAttribute(&quot;elite&quot;, strTag) &amp; &quot;&lt;br&gt;&quot;<br />'response.write GetAttribute(&quot;column&quot;, strTag) &amp; &quot;&lt;br&gt;&quot;<br />for i = 1 to GetAttribute(&quot;pagesize&quot;, strTag)<br />&nbsp;&nbsp; t = replace(text,&quot;{{id}}&quot;,i)<br />&nbsp;&nbsp; t = replace(t,&quot;{{title}}&quot;, i &amp; &quot;title&quot;)<br />&nbsp;&nbsp; ParseTag = ParseTag &amp; t &amp; Vbcrlf<br />next</p>
<p>case &quot;ARTICLE&quot;<br />'response.write GetAttribute(&quot;id&quot;, strTag) &amp; &quot;&lt;br&gt;&quot;<br />'response.write GetAttribute(&quot;content&quot;, strTag) &amp; &quot;&lt;br&gt;&quot;<br />end select<br />end function</p>
<p>function GetAttribute(ByVal strAttribute, ByVal strTag)<br />Dim objRegEx, Matches<br />Set objRegEx = New RegExp<br />objRegEx.Pattern = lCase(strAttribute) &amp; &quot;=&quot;&quot;[0-9a-zA-Z]*&quot;&quot;&quot;<br />objRegEx.IgnoreCase = True<br />objRegEx.Global = True<br />Set Matches = objRegEx.Execute(strTag)<br />if Matches.Count &gt; 0 then<br />GetAttribute = Split(Matches(0).Value,&quot;&quot;&quot;&quot;)(1)<br />else<br />GetAttribute = &quot;&quot;<br />end if<br />set Matches = nothing<br />set objRegEx = nothing<br />end function</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>配合缓存类：</p>
<p>class clsCache<br />private cache<br />private cacheName<br />private expireTime<br />private expireTimeName<br />private path</p>
<p>private sub class_initialize()<br />path=request.servervariables(&quot;url&quot;)<br />path=left(path,instrRev(path,&quot;/&quot;))<br />end sub</p>
<p>private sub class_terminate()<br />end sub</p>
<p>Public Property Get Version<br />Version=&quot;&quot;<br />End Property</p>
<p><br />public property get valid<br />if isempty(cache) or (not isdate(expireTime)) or (CDate(expireTime)&lt;now) then<br />vaild=false : clean()<br />else<br />valid=true<br />end if<br />end property</p>
<p>public property get value<br />if isempty(cache) or (not isDate(expireTime)) then<br />value=null<br />elseif CDate(expireTime)&lt;now then<br />value=null<br />else<br />value=cache<br />end if<br />end property</p>
<p>public property let name(str)<br />cacheName=str&amp;path<br />cache=application(cacheName)<br />expireTimeName=str&amp;&quot;expire&quot;&amp;path<br />expireTime=application(expireTimeName)<br />end property</p>
<p>public property let expire(tm)<br />expireTime=tm<br />application.Lock()<br />application(expireTimeName) =expireTime<br />application.UnLock()<br />end property</p>
<p><br />public sub add(varCache,varExpireTime)<br />if isempty(varCache) or not isDate(varExpireTime) then<br />exit sub<br />end if<br />cache=varCache<br />expireTime=varExpireTime<br />application.lock<br />application(cacheName)=cache<br />application(expireTimeName)=expireTime<br />application.unlock<br />end sub</p>
<p><br />public sub clean()<br />application.lock<br />application(cacheName)=empty<br />application(expireTimeName)=empty<br />Application.Contents.Remove(cacheName)<br />Application.Contents.Remove(expireTimeName)<br />application.unlock<br />cache=empty<br />expireTime=empty<br />end sub</p>
<p><br />public function verify(varcache2)<br />if typename(cache)&lt;&gt;typename(varcache2) then<br />verify=false<br />elseif typename(cache)=&quot;Object&quot; then<br />if cache is varcache2 then<br />&nbsp;&nbsp; verify=true<br />else<br />&nbsp;&nbsp; verify=false<br />end if<br />elseif typename(cache)=&quot;Variant()&quot; then<br />if join(cache,&quot;^&quot;)=join(varcache2,&quot;^&quot;) then<br />&nbsp;&nbsp; verify=true<br />else<br />&nbsp;&nbsp; verify=false<br />end if<br />else<br />if cache=varcache2 then<br />&nbsp;&nbsp; verify=true<br />else<br />&nbsp;&nbsp; verify=false<br />end if<br />end if<br />end function<br />end class</p>]]></summary>
	  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/myBlog.asp?s=396" /> 
	  <id>http://www.9702.com.cn/myBlog.asp?a=396</id>
  </entry>	
		
  <entry>
	  <title type="html"><![CDATA[ASP生成HTML（ASP+模板转成静态HTML）]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=395" label="ASP生成HTML（ASP+模板转成静态HTML）" /> 
	  <updated>2008-11-2 16:44:13</updated>
	  <published>2008-11-2 16:44:13</published>
		  <summary type="html"><![CDATA[<p style="TEXT-INDENT: 2em">我希望大家看到该标题就能让想象到它的功能：</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">1，WITH TEMPLET意思是，生成的页面架构将采用某个已设定的模板，在此之前我的一篇教程中介绍过，希望各位在看本教程之前对ASP采用模板应熟悉下。（当然，不看也没有问题，本教程同样会提及精华部分的：）</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
2，ASP2HTML。不要我再说ASP转变成HTML的好处了吧，呵呵，其中最值得知道的就是：静态HTML页和动态页对服务器的要求承受能力小得多，同样，静态HTML搜索几率远比动态页面的多得多。
<p>&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">那么，我现在需要处理的技术问题就是：</p>
<p style="TEXT-INDENT: 2em">1，如何实现模板技术？（先参看下上篇文章吧）</p>
<p style="TEXT-INDENT: 2em">2，如何实现2HTML技术？</p>
<p style="TEXT-INDENT: 2em">3，如何让模板技术与2HTML技术结合？</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">一、先进行技术原理分析</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">1，模板技术</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">2，2HTML技术又该如何实现呢？如何使得ASP页面转变为HTML？一般都会想到FSO组件，因为该组件能新建任何文件格式。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">那么其整个运行过程是怎么样的呢？</p>
<p style="TEXT-INDENT: 2em">a，提供信息输入页面进行信息收集；</p>
<p style="TEXT-INDENT: 2em">b，接受信息值先保存数据库，再FSO生成文件；</p>
<p style="TEXT-INDENT: 2em">c，技术性完成任务，显示刚被创建的HTML文件的路径地址。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">该技术的实现过程中有如下几个难点：</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">i，FSO生成的文件是直接放在一个大文件夹下，还是单独放在某个每日更新的子文件夹中？可能表述不准确，这样理解吧：相信通过FSO生成的文件随着时间的推移，文件会越来越多，管理也会越来越乱&hellip;&hellip;通常你可能看到一些地址诸如 http://www.xxx.com/a/2004-5-20/200405201111.html&nbsp;&nbsp; 可以分析得出应该是建立了当前日期的文件夹。这样，一天就是一个文件夹的页面内容，查看管理也就显得比较合理。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">ii，我在试图通过以上方法建立文件夹的时候，又发现了第二个问题。第一次通过FSO建立以当前日期命名的文件夹，没有问题。当我有新的文件需要生成时，因为是同一个程序，所以，其又将会执行建立同样的文件夹。此时，FSO组件会发现该路径已存在&hellip;&hellip;卡壳-_-! 继续处理，在首行添加代码：</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">On Error Resume Next</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">嘿嘿，达到自欺欺人、掩耳盗铃的效果。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">iii，文件夹是建立了，文件该如何建立呢？主要也就是文件名的生成。当然这个就需要自己来写个函数，功能就是如何生成文件名：）</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">function makefilename(fname)</p>
<p style="TEXT-INDENT: 2em">fname = fname '前fname为变量，后fname为函数参数引用</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;-&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot; &quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;:&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;PM&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;AM&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;上午&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;下午&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">makefilename = fname &amp; &quot;.html&quot;</p>
<p style="TEXT-INDENT: 2em">end function</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">引用函数则：</p>
<p style="TEXT-INDENT: 2em">&lt;%fname = makefilename(now())%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">其实嘛，就是以年月日时分秒命名的文件。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">iv，最后，生成的文件该如何查看到？当然需要把生成文件的路径保存的数据库中，并且添加到相对应的记录集中了。当然，这在下面的数据库设计时会提及到。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">3，模板技术和2HTML技术的结合：将模板中特殊代码的值替换为从表单接受过来的值，完成模板功能；将最终替换过的所有模板代码生成HTML文件。需要注意的是：替换应能将输入数据的格式或者支持UBB的代码彻底改变。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">二，再进行数据库设计</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">目前数据库的设计需要两个表：一个是存放模板数据的；一个是存放信息内容的。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">1，建立新数据库asp2html.mdb</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">2，设计新数据库表c_moban</p>
<p style="TEXT-INDENT: 2em">字段m_id（自动编号，主关键字）；字段m_html（备注类型）。</p>
<p style="TEXT-INDENT: 2em">并将下列完整的代码拷贝至m_html字段</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;html&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;head&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=hz&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;title&gt;Cnbruce.Com | ASP2HTML TEST&lt;/title&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;/head&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;body leftmargin=&quot;0&quot; topmargin=&quot;0&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;table width=&quot;100%&quot; height=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;2&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;tr align=&quot;right&quot; bgcolor=&quot;#CCCCCC&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; &lt;td height=&quot;20&quot; colspan=&quot;2&quot;&gt;$cntop$&lt;/td&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;/tr&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;tr valign=&quot;top&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; &lt;td width=&quot;25%&quot; bgcolor=&quot;#e5e5e5&quot;&gt;$cnleft$&lt;/td&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; &lt;td width=&quot;74%&quot; bgcolor=&quot;#f3f3f3&quot;&gt;$cnright$&lt;/td&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;/tr&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;/table&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;/body&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;/html&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">3，设计新数据库表c_news</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">字段c_id：自动编号，主关键字</p>
<p style="TEXT-INDENT: 2em">字段c_title：文本类型，保存文章标题</p>
<p style="TEXT-INDENT: 2em">字段c_content：备注类型，保存文章内容</p>
<p style="TEXT-INDENT: 2em">字段c_filepath：文本类型，保持生成文件的路径地址</p>
<p style="TEXT-INDENT: 2em">字段c_time：日期/时间类型，默认值：Now()</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">三，页面需求设计</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">1，首先建立一个存放HTML页的文件夹</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">在文件同一目录下，建立文件夹newsfile，夹子内部主要存放生成的HTML页面，当然内部还会采用程序方式建立以日期命名的子文件夹，以方便浏览以及管理。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">2，功能函数页面lib.asp</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">'生成文件名的函数</p>
<p style="TEXT-INDENT: 2em">function makefilename(fname)</p>
<p style="TEXT-INDENT: 2em">fname = fname</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;-&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot; &quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;:&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;PM&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;AM&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;上午&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">fname = replace(fname,&quot;下午&quot;,&quot;&quot;)</p>
<p style="TEXT-INDENT: 2em">makefilename=fname &amp; &quot;.shtml&quot;</p>
<p style="TEXT-INDENT: 2em">end function</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">'保持数据格式不变的函数</p>
<p style="TEXT-INDENT: 2em">Function htmlencode(fString) <br />'If not isnull(fString) then <br />'fString = replace(fString, &quot;&gt;&quot;, &quot;&gt;&quot;) <br />'fString = replace(fString, &quot;&lt;&quot;, &quot;&lt;&quot;) <br />'fString = Replace(fString, CHR(32), &quot; &quot;) <br />'fString = Replace(fString, CHR(9), &quot; &quot;) <br />'fString = Replace(fString, CHR(34), &quot;&quot;&quot;) <br />'fString = Replace(fString, CHR(39), &quot;'&quot;) <br />'fString = Replace(fString, CHR(13), &quot;&quot;) <br />'fString = Replace(fString, CHR(10) &amp; CHR(10), &quot;&lt;/p&gt;&lt;p&gt; &quot;) <br />'fString = Replace(fString, CHR(10), &quot;&lt;br&gt; &quot;)</p>
<p style="TEXT-INDENT: 2em">If Not IsNull(fString) Then<br />fString = trim(fString)<br />fString = replace(fString, &quot;;&quot;, &quot;；&quot;)&nbsp;&nbsp;&nbsp;&nbsp; '分号过滤<br />fString = replace(fString, &quot;--&quot;, &quot;&mdash;&mdash;&quot;) '--过滤<br />fString = replace(fString, &quot;%20&quot;, &quot;&quot;)&nbsp;&nbsp;&nbsp; '特殊字符过滤<br />fString = replace(fString, &quot;==&quot;, &quot;&quot;)&nbsp;&nbsp;&nbsp;&nbsp; '==过滤<br />fString = replace(fString, &quot;&gt;&quot;, &quot;&amp;gt;&quot;)<br />fString = replace(fString, &quot;&lt;&quot;, &quot;&amp;lt;&quot;)<br />fString = Replace(fString, CHR(32), &quot; &quot;)&nbsp;&nbsp; '&amp;nbsp;<br />fString = Replace(fString, CHR(9), &quot; &quot;)&nbsp;&nbsp;&nbsp; '&amp;nbsp;<br />fString = Replace(fString, CHR(34), &quot;&amp;quot;&quot;)<br />fString = Replace(fString, CHR(39), &quot;&amp;#39;&quot;) '单引号过滤<br />fString = Replace(fString, CHR(13), &quot;&quot;)<br />fString = Replace(fString, CHR(10) &amp; CHR(10), &quot;&lt;/P&gt;&lt;P&gt; &quot;)<br />fString = Replace(fString, CHR(10), &quot;&lt;BR&gt; &quot;)</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">htmlencode = fString <br />End If <br />End Function</p>
<p style="TEXT-INDENT: 2em">Function uhtmlencode(fString) <br />If not isnull(fString) then <br />fString = Replace(fString, &quot; &quot;, CHR(32)) <br />fString = Replace(fString, &quot; &quot;, CHR(9)) <br />fString = Replace(fString, &quot;&amp;#34;&quot;, CHR(34)) <br />fString = Replace(fString, &quot;&amp;#39;&quot;, CHR(39)) <br />fString = Replace(fString, &quot;&quot;, CHR(13)) <br />fString = Replace(fString, &quot;&lt;/p&gt;&lt;p&gt; &quot;, CHR(10) &amp; CHR(10)) <br />fString = Replace(fString, &quot;&lt;br&gt; &quot;, CHR(10)) <br />uhtmlencode = fString <br />End If <br />End Function</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">3，数据库连接页面conn.asp</p>
<p style="TEXT-INDENT: 2em">完成数据库的字符串连接方法</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)</p>
<p style="TEXT-INDENT: 2em">connstr = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;&amp;Server.MapPath(&quot;asp2html.mdb&quot;)</p>
<p style="TEXT-INDENT: 2em">conn.Open connstr</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">4，信息输入页面add.html</p>
<p style="TEXT-INDENT: 2em">其实很简单：）就是表单嘛。注意action是跳转到addit.asp</p>
<p style="TEXT-INDENT: 2em">&lt;form action=&quot;addit.asp&quot; method=&quot;post&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">title:&lt;input type=&quot;text&quot; &gt;&lt;br&gt;</p>
<p style="TEXT-INDENT: 2em">Content:&lt;br&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;textarea rows=&quot;8&quot; cols=&quot;30&quot;&gt;&lt;/textarea&gt;&lt;br&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;input type=&quot;submit&quot; value=&quot;Add&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;input type=&quot;reset&quot; value=&quot;Reset&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;/form&gt;</p>
<p style="TEXT-INDENT: 2em">5，处理数据功能显示页面addit.asp</p>
<p style="TEXT-INDENT: 2em">首先是处理接受过来的数据，并将值写入数据库；接着将模板代码进行引用，并将其中特殊代码转换为接受值，最终通过FSO生成HTML页面。其中需要注意的还有，生成文件的路径地址保存至数据库表。</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%'容错处理</p>
<p style="TEXT-INDENT: 2em">On Error Resume Next</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;!--#include file=&quot;conn.asp&quot; --&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;!--#include file=&quot;lib.asp&quot; --&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%'接受传递值</p>
<p style="TEXT-INDENT: 2em">c_title=request.form(&quot;c_title&quot;)</p>
<p style="TEXT-INDENT: 2em">c_content=request.form(&quot;c_content&quot;)</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%'生成HTML文件名，建立文件夹，指定文件路径</p>
<p style="TEXT-INDENT: 2em">fname = makefilename(now())&nbsp;&nbsp; 'makefilename为自定义函数</p>
<p style="TEXT-INDENT: 2em">folder = &quot;newsfile/&quot;&amp;date()&amp;&quot;/&quot;</p>
<p style="TEXT-INDENT: 2em">filepath = folder&amp;fname</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%'将接受值及路径保持至数据库表</p>
<p style="TEXT-INDENT: 2em">sql = &quot;Select * from c_news&quot;</p>
<p style="TEXT-INDENT: 2em">Set rs = Server.CreateObject (&quot;ADODB.Recordset&quot;)</p>
<p style="TEXT-INDENT: 2em">rs.Open sql,conn,3,2</p>
<p style="TEXT-INDENT: 2em">rs.addnew</p>
<p style="TEXT-INDENT: 2em">rs(&quot;c_title&quot;)=c_title</p>
<p style="TEXT-INDENT: 2em">rs(&quot;c_content&quot;)=c_content</p>
<p style="TEXT-INDENT: 2em">rs(&quot;c_filepath&quot;)=filepath</p>
<p style="TEXT-INDENT: 2em">rs.update</p>
<p style="TEXT-INDENT: 2em">rs.close</p>
<p style="TEXT-INDENT: 2em">Set rs = Nothing</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%'打开模板代码，并将其中特殊代码转变为接受值</p>
<p style="TEXT-INDENT: 2em">sql1=&quot;select m_id,m_html from c_moban where m_id=1&quot;</p>
<p style="TEXT-INDENT: 2em">set rs1=Server.CreateObject(&quot;adodb.recordset&quot;)</p>
<p style="TEXT-INDENT: 2em">rs1.open sql1,conn,1,1</p>
<p style="TEXT-INDENT: 2em">mb_code=rs1(&quot;m_html&quot;)</p>
<p style="TEXT-INDENT: 2em">rs1.close</p>
<p style="TEXT-INDENT: 2em">set rs1=nothing</p>
<p style="TEXT-INDENT: 2em">conn.close</p>
<p style="TEXT-INDENT: 2em">set conn=nothing</p>
<p style="TEXT-INDENT: 2em">c_title=htmlencode(c_title)</p>
<p style="TEXT-INDENT: 2em">c_content=htmlencode(c_content)</p>
<p style="TEXT-INDENT: 2em">mb_code=replace(mb_code,&quot;$cntop$&quot;,now())</p>
<p style="TEXT-INDENT: 2em">mb_code=replace(mb_code,&quot;$cnleft$&quot;,c_title)</p>
<p style="TEXT-INDENT: 2em">mb_code=replace(mb_code,&quot;$cnright$&quot;,c_content)</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%'生成HTML页面</p>
<p style="TEXT-INDENT: 2em">Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)</p>
<p style="TEXT-INDENT: 2em">fso.CreateFolder(Server.MapPath(folder))</p>
<p style="TEXT-INDENT: 2em">Set fout = fso.CreateTextFile(Server.MapPath(filepath))</p>
<p style="TEXT-INDENT: 2em">fout.WriteLine mb_code</p>
<p style="TEXT-INDENT: 2em">fout.close</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">文章添加成功，&lt;a href=&quot;showit.asp&quot;&gt;浏览&lt;/a&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">6，显示数据库表记录，并做指向HTML页的链接：showit.asp</p>
<p style="TEXT-INDENT: 2em">&lt;!--#include file=&quot;conn.asp&quot; --&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;!--#include file=&quot;lib.asp&quot; --&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">Set rs = Server.CreateObject (&quot;ADODB.Recordset&quot;)</p>
<p style="TEXT-INDENT: 2em">sql = &quot;Select * from c_news order by c_id desc&quot;</p>
<p style="TEXT-INDENT: 2em">rs.Open sql,conn,1,1</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">if rs.EOF and rs.BOF then</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp; response.write (&quot;暂时还没有文章，&lt;a href=add.html&gt;添加&lt;/a&gt;&quot;)</p>
<p style="TEXT-INDENT: 2em">else</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp; Do Until rs.EOF</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;table width=&quot;758&quot; border=&quot;0&quot; align=&quot;center&quot; cellpadding=&quot;3&quot; cellspacing=&quot;1&quot; bgcolor=&quot;#000000&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td width=&quot;159&quot; align=&quot;right&quot; bordercolor=&quot;#CCCCCC&quot; bgcolor=&quot;#CCCCCC&quot;&gt;&lt;%=rs(&quot;c_time&quot;)%&gt;&lt;/td&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td width=&quot;591&quot; bordercolor=&quot;#f3f3f3&quot; bgcolor=&quot;#f3f3f3&quot;&gt;&lt;a href=&lt;%=rs(&quot;c_filepath&quot;)%&gt; target=&quot;a_blank&quot;&gt;&lt;%=rs(&quot;c_title&quot;)%&gt;&lt;/a&gt;&lt;/td&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;tr&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign=&quot;top&quot; align=&quot;right&quot; bordercolor=&quot;#ececec&quot; bgcolor=&quot;#ececec&quot;&gt;[&lt;a href=del.asp?c_id=&lt;%=rs(&quot;c_id&quot;)%&gt;&gt;Dell&lt;/a&gt;][&lt;a href=change.asp?c_id=&lt;%=rs(&quot;c_id&quot;)%&gt;&gt;Edit&lt;/a&gt;][&lt;a href=&quot;add.html&quot;&gt;Add&lt;/a&gt;]&lt;/td&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;td valign=&quot;top&quot; bordercolor=&quot;#FFFFFF&quot; bgcolor=&quot;#FFFFFF&quot;&gt;&lt;%=htmlencode(rs(&quot;c_content&quot;))%&gt;&lt;/td&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/tr&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;/table&gt;&lt;br&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; rs.MoveNext</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp; Loop</p>
<p style="TEXT-INDENT: 2em">end if</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">rs.close</p>
<p style="TEXT-INDENT: 2em">Set rs = Nothing</p>
<p style="TEXT-INDENT: 2em">conn.close</p>
<p style="TEXT-INDENT: 2em">set conn=Nothing</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">7，修改数据内容页change.asp</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">修改数据内容，同时也需要修改更新对应的HTML页面。修改其实就是重新生成文件，且文件名和之前一样，类似文件的覆盖。</p>
<p style="TEXT-INDENT: 2em">&lt;!--#include file=&quot;conn.asp&quot; --&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;!--#include file=&quot;lib.asp&quot; --&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%id=request.querystring(&quot;c_id&quot;)%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">if request.form(&quot;submit&quot;)=&quot;change&quot; then</p>
<p style="TEXT-INDENT: 2em">c_title=request.form(&quot;c_title&quot;)</p>
<p style="TEXT-INDENT: 2em">c_content=request.form(&quot;c_content&quot;)</p>
<p style="TEXT-INDENT: 2em">c_id=request.form(&quot;c_id&quot;)</p>
<p style="TEXT-INDENT: 2em">c_filepath=request.form(&quot;c_filepath&quot;)</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">Set rs = Server.CreateObject (&quot;ADODB.Recordset&quot;)</p>
<p style="TEXT-INDENT: 2em">sql = &quot;Select * from c_news where c_id=&quot;&amp;c_id</p>
<p style="TEXT-INDENT: 2em">rs.Open sql,conn,3,2</p>
<p style="TEXT-INDENT: 2em">rs(&quot;c_title&quot;)=c_title</p>
<p style="TEXT-INDENT: 2em">rs(&quot;c_content&quot;)=c_content</p>
<p style="TEXT-INDENT: 2em">rs(&quot;c_time&quot;)=now()</p>
<p style="TEXT-INDENT: 2em">rs.update</p>
<p style="TEXT-INDENT: 2em">rs.close</p>
<p style="TEXT-INDENT: 2em">Set rs = Nothing</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%'打开模板代码，并将其中特殊代码转变为接受值</p>
<p style="TEXT-INDENT: 2em">sql1=&quot;select m_id,m_html from c_moban where m_id=1&quot;</p>
<p style="TEXT-INDENT: 2em">set rs1=Server.CreateObject(&quot;adodb.recordset&quot;)</p>
<p style="TEXT-INDENT: 2em">rs1.open sql1,conn,1,1</p>
<p style="TEXT-INDENT: 2em">mb_code=rs1(&quot;m_html&quot;)</p>
<p style="TEXT-INDENT: 2em">rs1.close</p>
<p style="TEXT-INDENT: 2em">set rs1=nothing</p>
<p style="TEXT-INDENT: 2em">conn.close</p>
<p style="TEXT-INDENT: 2em">set conn=nothing</p>
<p style="TEXT-INDENT: 2em">c_title=htmlencode(c_title)</p>
<p style="TEXT-INDENT: 2em">c_content=htmlencode(c_content)</p>
<p style="TEXT-INDENT: 2em">mb_code=replace(mb_code,&quot;$cntop$&quot;,now())</p>
<p style="TEXT-INDENT: 2em">mb_code=replace(mb_code,&quot;$cnleft$&quot;,c_title)</p>
<p style="TEXT-INDENT: 2em">mb_code=replace(mb_code,&quot;$cnright$&quot;,c_content)</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%'生成HTML页面</p>
<p style="TEXT-INDENT: 2em">Set fso = Server.CreateObject(&quot;Scripting.FileSystemObject&quot;)</p>
<p style="TEXT-INDENT: 2em">Set fout = fso.CreateTextFile(Server.MapPath(c_filepath))</p>
<p style="TEXT-INDENT: 2em">fout.WriteLine mb_code</p>
<p style="TEXT-INDENT: 2em">fout.close</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;%response.redirect(&quot;showit.asp&quot;)%&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;%end if%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">if id&lt;&gt;&quot;&quot; then</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; Set rs = Server.CreateObject (&quot;ADODB.Recordset&quot;)</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; sql=&quot;select * from c_news where c_id=&quot;&amp;id</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; rs.Open sql,conn,1,1</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; c_id=rs(&quot;c_id&quot;)</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; c_filepath=rs(&quot;c_filepath&quot;)</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; c_title=rs(&quot;c_title&quot;)</p>
<p style="TEXT-INDENT: 2em">&nbsp;&nbsp;&nbsp; c_content=rs(&quot;c_content&quot;)</p>
<p style="TEXT-INDENT: 2em">end if</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;form action=&quot;change.asp&quot; method=&quot;post&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">title:&lt;input type=&quot;text&quot; value=&lt;%=c_title%&gt;&gt;&lt;br&gt;</p>
<p style="TEXT-INDENT: 2em">Content:&lt;br&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;textarea rows=&quot;8&quot; cols=&quot;30&quot;&gt;&lt;%=c_content%&gt;&lt;/textarea&gt;&lt;br&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;input type=&quot;submit&quot; value=&quot;change&quot; &gt;</p>
<p style="TEXT-INDENT: 2em">&lt;input type=&quot;reset&quot; value=&quot;Reset&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;input type=&quot;hidden&quot; value=&quot;&lt;%=id%&gt;&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;input type=&quot;hidden&quot; value=&quot;&lt;%=c_filepath%&gt;&quot;&gt;</p>
<p style="TEXT-INDENT: 2em">&lt;/form&gt;</p>
<p style="TEXT-INDENT: 2em">8，删除记录页del.asp</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">同样！删除，除了删除数据库表中的记录，与其对应的HTML页面也需删除。代码如下：</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;!--#include file=&quot;conn.asp&quot; --&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%</p>
<p style="TEXT-INDENT: 2em">c_id = request.querystring(&quot;c_id&quot;)</p>
<p style="TEXT-INDENT: 2em">sql = &quot;Select * from c_news where c_id=&quot;&amp;c_id</p>
<p style="TEXT-INDENT: 2em">Set rs = Server.CreateObject (&quot;ADODB.Recordset&quot;)</p>
<p style="TEXT-INDENT: 2em">rs.Open sql,conn,2,3</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">filepath=rs(&quot;c_filepath&quot;)</p>
<p style="TEXT-INDENT: 2em">Set fso = CreateObject(&quot;Scripting.FileSystemObject&quot;)</p>
<p style="TEXT-INDENT: 2em">fso.DeleteFile(Server.mappath(filepath))</p>
<p style="TEXT-INDENT: 2em">Set fso = nothing</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">rs.delete</p>
<p style="TEXT-INDENT: 2em">rs.close</p>
<p style="TEXT-INDENT: 2em">Set rs = Nothing</p>
<p style="TEXT-INDENT: 2em">conn.close</p>
<p style="TEXT-INDENT: 2em">set conn=nothing</p>
<p style="TEXT-INDENT: 2em">%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&lt;%response.redirect(&quot;showit.asp&quot;)%&gt;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">四，其它功能</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">模板管理页面：</p>
<p style="TEXT-INDENT: 2em">&nbsp;</p>
<p style="TEXT-INDENT: 2em">不会每次都是打开数据库表进行增加或者修改模板代码吧，所以，管理代码的页面程序不能少了，自己捣鼓下应该很简单的。当然，之前管理员的登录认证程序就不在书中交代了：）还有，如果设计了多个模板，那么在发表信息的时候应添加模板选择单选框，同样在执行转换HTML时，SQL选择的不同m_id了。</p>]]></summary>
	  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/myBlog.asp?s=395" /> 
	  <id>http://www.9702.com.cn/myBlog.asp?a=395</id>
  </entry>	
		
  <entry>
	  <title type="html"><![CDATA[ASP模板应用技巧]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=394" label="ASP模板应用技巧" /> 
	  <updated>2008-11-2 16:42:44</updated>
	  <published>2008-11-2 16:42:44</published>
		  <summary type="html"><![CDATA[<span class="checkoutHeader"><strong>本文详细介绍所谓的模板，就是设计完工的标准的HTML代码，其中需要由程序实现的功能部分将采用特殊字符串代替。</strong></span>
<p>&nbsp;</p>
<div class="content">所以，梦想着那么大段的程序代码变成几个简单的字符代替，这样只要设计好页面把该功能插入就OK了。其实这也简单，只需将实现该功能的程序代码做成子程序，然后主页调用就可以了。
<p>很多时候，在博客中国，你会选择到很多的模板，甚至有可能自己来设计；或者采用猪飞飞BLOG的各大站长都将其站点改得不近相同&hellip;&hellip;这些，我们都归功于ASP采用模板的功能。</p>
<p>那下面偶就借花献佛，将模板拿来分析，以馈各位朋友。</p>
<p>首先，模板需要在线修改，则应采用数据库保存模板代码</p>
<p>所谓的模板，就是设计完工的标准的HTML代码，其中需要由程序实现的功能部分将采用特殊字符串代替。这些特殊字符串需要在显示的时候被编译为对应的功能。</p>
<p>2，假设第一模板内容代码</p>
<p>将下列代码拷贝到m_html字段中</p>
<p>&lt;html&gt;</p>
<p>&lt;head&gt;</p>
<p>&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot;&gt;</p>
<p>&lt;title&gt;testmb&lt;/title&gt;</p>
<p>&lt;/head&gt;</p>
<p>&lt;body leftmargin=&quot;0&quot; topmargin=&quot;0&quot;&gt;</p>
<p>&lt;table width=&quot;100%&quot; height=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;2&quot;&gt;</p>
<p> &lt;tr align=&quot;right&quot; bgcolor=&quot;#CCCCCC&quot;&gt;</p>
<p> &lt;td height=&quot;20&quot; colspan=&quot;2&quot;&gt;$cntoplt;/td&gt;</p>
<p> &lt;/tr&gt;</p>
<p> &lt;tr valign=&quot;top&quot;&gt;</p>
<p> &lt;td width=&quot;25%&quot; bgcolor=&quot;#e5e5e5&quot;&gt;$cnleftlt;/td&gt;</p>
<p> &lt;td width=&quot;74%&quot; bgcolor=&quot;#f3f3f3&quot;&gt;$cnrightlt;/td&gt;</p>
<p> &lt;/tr&gt;</p>
<p>&lt;/table&gt;</p>
<p>&lt;/body&gt;</p>
<p>&lt;/html&gt;</p>
<p>注意$cntop$、$cnleft$、$cnright$，它们将要实现某些具体的程序功能</p>
<p>3，建立数据库连接文件conn.asp</p>
<p>&lt;%</p>
<p>set conn= Server.CreateObject(&quot;ADODB.Connection&quot;)</p>
<p>connstr = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot;&amp;Server.MapPath(&quot;testmb.mdb&quot;)</p>
<p>conn.Open connstr</p>
<p>%&gt;</p>
<p>4，建立特殊字符串转换所需要的库文件lib.asp</p>
<p>该文件的主要作用是将实现某些功能的ASP程序做成字程序，以方便调用。</p>
<p>&lt;%</p>
<p>dim topcode</p>
<p>sub cntop()</p>
<p> topcode=&quot;现在时间是：&quot;</p>
<p> topcode=topcode&amp;now()</p>
<p>end sub</p>
<p>dim leftcode,i</p>
<p>sub cnleft()</p>
<p> for i = 1 to 5</p>
<p> leftcode=leftcode&amp;&quot;&lt;p&gt;cnbruce.com&quot;</p>
<p> next</p>
<p>end sub</p>
<p>dim rightcode</p>
<p>sub cnright()</p>
<p> for i = 1 to 9</p>
<p> rightcode=rightcode&amp;&quot;&lt;hr color=&quot;&amp;i&amp;i&amp;i&amp;i&amp;i&amp;i&amp;&quot;&gt;&quot;</p>
<p> next</p>
<p>end sub</p>
<p>%&gt;</p>
<p>5，最后，调用数据库中的模板代码，将特殊字符串转换。</p>
<p>&lt;!--#include file=&quot;conn.asp&quot; --&gt;</p>
<p>&lt;!--#include file=&quot;lib.asp&quot; --&gt;</p>
<p>&lt;%</p>
<p>sql=&quot;select * from moban where m_id=1&quot;</p>
<p>set rs=Server.CreateObject(&quot;adodb.recordset&quot;)</p>
<p>rs.open sql,conn,1,1</p>
<p>mb_code=rs(&quot;m_html&quot;)</p>
<p>rs.close</p>
<p>set rs=nothing</p>
<p>cntop()</p>
<p>mb_code=replace(mb_code,&quot;$cntop$&quot;,topcode)</p>
<p>cnleft()</p>
<p>mb_code=replace(mb_code,&quot;$cnleft$&quot;,leftcode)</p>
<p>cnright()</p>
<p>mb_code=replace(mb_code,&quot;$cnright$&quot;,rightcode)　</p>
<p>response.write mb_code</p>
<p>%&gt;</p>
<p>该页主要作用是将模板代码进行显示，并将其中的特殊代码转变为相对应子程序功能。</p>
</div>]]></summary>
	  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/myBlog.asp?s=394" /> 
	  <id>http://www.9702.com.cn/myBlog.asp?a=394</id>
  </entry>	
		
  <entry>
	  <title type="html"><![CDATA[ASP无组件同时上传多张图片并存入数据库]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=393" label="ASP无组件同时上传多张图片并存入数据库" /> 
	  <updated>2008-10-30 10:03:21</updated>
	  <published>2008-10-30 10:03:21</published>
		  <summary type="html"><![CDATA[<p>&nbsp; &lt;html&gt; &nbsp; <br />&nbsp; &lt;body&gt; &nbsp; <br />&nbsp; &lt;form &nbsp; name=form1&gt; &nbsp; <br />&nbsp; &lt;input &nbsp; type=file &nbsp; name=&quot;file1&quot;&gt; &nbsp; <br />&nbsp; &lt;input &nbsp; type=file &nbsp; name=&quot;file2&quot;&gt; &nbsp; <br />&nbsp; &lt;input &nbsp; type=button &nbsp; onclick=send(); &nbsp; value=&quot;提交&quot;&gt; &nbsp; <br />&nbsp; &lt;/form&gt; &nbsp; <br />&nbsp; &lt;script&gt; &nbsp; <br />&nbsp; function &nbsp; send(){ &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; var &nbsp; xml_dom &nbsp; = &nbsp; new &nbsp; ActiveXObject(&quot;MSXML2.DOMDocument&quot;); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; xml_dom.loadXML('&lt;?xml &nbsp; version=&quot;1.0&quot; &nbsp; ?&gt; &nbsp; &lt;root/&gt;'); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; xml_dom.documentElement.setAttribute(&quot;xmlns:dt&quot;, &nbsp; &quot;urn:schemas-microsoft-com:datatypes&quot;); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; for &nbsp; (i=0;i&lt;document.form1.length;i++) &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(document.form1[i].type=='file'){ &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if(document.form1[i].value!=&quot;&quot;){ &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; upnode(xml_dom,document.form1[i]); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; var &nbsp; xmlhttp &nbsp; = &nbsp; new &nbsp; ActiveXObject(&quot;Microsoft.XMLHTTP&quot;); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; xmlhttp.open(&quot;POST&quot;,&quot;b.asp&quot;,false); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; xmlhttp.send(xml_dom); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; alert(xmlhttp.ResponseText); &nbsp; <br />&nbsp; } &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; function &nbsp; upnode(dom_obj,file_obj){ &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; var &nbsp; nd &nbsp; = &nbsp; dom_obj.createElement(file_obj.name); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; nd.dataType &nbsp; = &nbsp; &quot;bin.base64&quot;; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; var &nbsp; ado_stream &nbsp; = &nbsp; new &nbsp; ActiveXObject(&quot;ADODB.Stream&quot;); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.Type &nbsp; =1; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.Open(); &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.LoadFromFile(file_obj.value); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; nd.nodeTypedValue &nbsp; = &nbsp; ado_stream.Read(-1); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.Close(); &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; dom_obj.documentElement.appendChild(nd); &nbsp; <br />&nbsp; } &nbsp; <br />&nbsp; &lt;/script&gt; &nbsp; <br />&nbsp; &lt;/html&gt;</p>
<p>第二个文件 &nbsp; <br />&nbsp; //没有对文件名处理 &nbsp; <br />&nbsp; &lt;% &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; Response.Expires &nbsp; = &nbsp; 0 &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; dim &nbsp; ado_stream &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; dim &nbsp; xml_dom &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; xml_dom &nbsp; = &nbsp; Server.CreateObject(&quot;MSXML2.DOMDocument&quot;) &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; xml_dom.load(request) &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; for &nbsp; i= &nbsp; 0 &nbsp; to &nbsp; (xml_dom.documentElement.childNodes.length &nbsp; -1) &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; list=xml_dom.documentElement.childNodes.item(i) &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; saveas &nbsp; list &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; next &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; sub &nbsp; savetodb() &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; con=session(&quot;con&quot;) &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; end &nbsp; sub &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; sub &nbsp; saveas(nd) &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; ado_stream &nbsp; = &nbsp; Server.CreateObject(&quot;ADODB.Stream&quot;) &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.Type &nbsp; = &nbsp; 1 &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.open &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.Write &nbsp; nd.nodeTypedValue &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.SaveToFile &nbsp; &quot;c:\1.vbs&quot;,2 &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; ado_stream.close &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; ado_stream &nbsp; = &nbsp; Nothing &nbsp; &nbsp; <br />&nbsp; end &nbsp; sub &nbsp; <br />&nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; xml_dom &nbsp; = &nbsp; Nothing &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; Response.Write &nbsp; &quot;上传成功&quot; &nbsp; <br />&nbsp; %&gt;&nbsp;&nbsp; <br /></p>
<p>//原来你要保存到数据库 &nbsp; <br />&nbsp; 第二个文件的补丁 &nbsp; <br />&nbsp; sub &nbsp; savetodb(nd) &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; rs=server.CreateObject(&quot;adodb.recordset&quot;) &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rs.Open &nbsp; &quot;SELECT &nbsp; * &nbsp; FROM &nbsp; xxx&quot;,con,1,3 &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rs.addnew &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rs(&quot;fujian&quot;).AppendChunk &nbsp; nd.nodeTypedValue &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rs(&quot;fjmc&quot;)= &nbsp; &quot;1.vbs&quot; &nbsp; //文件名称你可以想办法获得，如果你不懂xml就有点麻烦 &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rs(&quot;fjsx&quot;) &nbsp; = &nbsp; &quot;application/octet-stream&quot; &nbsp; //很显然，这是个重要的东西，不然输出就麻烦了 &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rs.update &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rs.close &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; rs=nothing &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; set &nbsp; con=nothing &nbsp; <br />&nbsp; end &nbsp; sub</p>
<p>&nbsp;</p>]]></summary>
	  <link rel="alternate" type="text/html" href="http://www.9702.com.cn/myBlog.asp?s=393" /> 
	  <id>http://www.9702.com.cn/myBlog.asp?a=393</id>
  </entry>	
		
  <entry>
	  <title type="html"><![CDATA[上传图片至数据库内功能的实现]]></title>
	  <author>
		 <name>mosquito_520@163.com</name>
		 <uri>http://www.9702.com.cn/</uri>
		 <email>mosquito_520@163.com</email>
	  </author>
	  <category term="" scheme="http://www.9702.com.cn/myBlog.asp?s=392" label="上传图片至数据库内功能的实现" /> 
	  <updated>2008-10-30 9:52:08</updated>
	  <published>2008-10-30 9:52:08</published>
		  <summary type="html"><![CDATA[<div class="postTitle"><span style="FONT-FAMILY: Verdana"><span style="FONT-SIZE: 10pt"><span style="FONT-FAMILY: Verdana">&nbsp;&nbsp;&nbsp; 一般的无组件上传类，其上传过程是将图片先保存到指定文件夹，与此同时将该路径保存至数据库字段的。显示图片则是根据数据库表中的路径字段对应显示的。当然有关图片的管理，比如删除：只删除了路径，实际的图片需要根据该路径通过FSO进行删除&hellip;&hellip;<br /><br />那有没有这样一种情况：将图片直接作为一个字段的值保存。对图片的操作就象是对数据字段的操作一样熟练。答案是肯定的，只是将该字段的类型设为OLE对象<br /><br />知识点：OLE&nbsp;对象字段用来存储诸如&nbsp;Microsoft&nbsp;Word&nbsp;或&nbsp;Microsoft&nbsp;EXCEL&nbsp;文档、图片、声音的数据以及在别的程序中创建的其他类型的二进制数据。OLE&nbsp;对象可以链接或嵌入到&nbsp;Microsoft&nbsp;Access&nbsp;表的字段中。<br /><br />一、设计数据库testimg.mdb<br /><br />为方便调试，设计表imgurl，其中两个字段：id（自动编号、关键字）、img（OLE&nbsp;对象）<br /><br />二、连接数据库文件conn.asp<br /><br />
<div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<div><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">%<br /><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" />db_path</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">testimg.mdb&quot;</span><span style="COLOR: #000000"><br /><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span><span style="COLOR: #0000ff">set</span><span style="COLOR: #000000">&nbsp;conn</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">server.</span><span style="COLOR: #0000ff">CreateObject</span><span style="COLOR: #000000">(</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">ADODB.connection</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">)<br /><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" />connstr</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">driver={Microsoft&nbsp;Access&nbsp;Driver&nbsp;(*.mdb)};dbq=</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&amp;</span><span style="COLOR: #000000">server.MapPath(db_path)<br /><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" />conn.open&nbsp;connstr<br /><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" />%</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" /></span></div>
</div>
<br />三、提供上传图片的表单页面upload.html<br /><br />
<div style="BORDER-RIGHT: windowtext 0.5pt solid; PADDING-RIGHT: 5.4pt; BORDER-TOP: windowtext 0.5pt solid; PADDING-LEFT: 5.4pt; BACKGROUND: #e6e6e6; PADDING-BOTTOM: 4px; BORDER-LEFT: windowtext 0.5pt solid; WIDTH: 98%; WORD-BREAK: break-all; PADDING-TOP: 4px; BORDER-BOTTOM: windowtext 0.5pt solid">
<div><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" /><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">form&nbsp;action</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">upload.asp</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;method</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">post</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&nbsp;enctype</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">multipart/form-data</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">&gt;</span><span style="COLOR: #000000"><br /><img src="http://www.cnblogs.com/Images/OutliningIndicators/None.gif" align="top" alt="" />　　</span><span style="COLOR: #000000">&lt;</span><span style="COLOR: #000000">input&nbsp;type</span><span style="COLOR: #000000">=</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: #000000">file</span><span style="COLOR: #000000">&quot;</span><span style="COLOR: 