asp动态调用不同include文件方法

作者:秋水无恨 来源:蓝色理想 时间:2007-09-26 14:22:00 

受<! #include file="filename.asp" --> 宏限制
必须存在该文件并且会预先编译(不管前面是否加以条件)

经常有这样的要求,根据不同的需求要求include不同的文件如各个人的不同设置,所以要求能动态include文件。

代码如下:


<%
Function include(filename)
 Dim re,content,fso,f,aspStart,aspEnd

 set fso=CreateObject("Scripting.FileSystemObject")
 set f=fso.OpenTextFile(server.mappath(filename))
 content=f.ReadAll
 f.close
 set f=nothing
 set fso=nothing

 set re=new RegExp
 re.pattern="^\s*="
 aspEnd=1
 aspStart=inStr(aspEnd,content,"<%")+2
 do while aspStart>aspEnd+1
  Response.write Mid(content,aspEnd,aspStart-aspEnd-2)
  aspEnd=inStr(aspStart,content,"%\>")+2
  Execute(re.replace(Mid(content,aspStart,aspEnd-aspStart-2),"Response.Write "))
  aspStart=inStr(aspEnd,content,"<%")+2
 loop
 Response.write Mid(content,aspEnd)
 set re=nothing
End Function
%>


使用范例:include("youinc.asp")

标签:include,文件,asp
0
投稿

猜你喜欢

  • python如何将图片转换素描画

    2022-05-26 23:17:49
  • 一文理解Goland协程调度器scheduler的实现

    2024-05-22 17:44:53
  • Python实现GPU加速的基本操作

    2021-07-30 05:10:34
  • python继承threading.Thread实现有返回值的子类实例

    2023-06-07 19:01:15
  • python Matplotlib画图之调整字体大小的示例

    2023-03-27 09:43:30
  • 详解微信小程序缓存--缓存时效性

    2024-04-28 10:19:27
  • python中的print()输出

    2023-06-27 18:07:03
  • 间歇向上无缝翻滚代码

    2008-05-05 12:30:00
  • ORM Django 终端打印 SQL 语句实现解析

    2023-08-30 04:56:39
  • Python-numpy实现灰度图像的分块和合并方式

    2021-06-14 16:24:27
  • PyQt 线程类 QThread使用详解

    2021-09-18 05:51:37
  • python BeautifulSoup使用方法详解

    2021-04-22 12:09:55
  • python数据分析基础知识之shape()函数的使用教程

    2023-06-11 04:03:56
  • django foreignkey(外键)的实现

    2023-03-15 17:35:51
  • python把数组中的数字每行打印3个并保存在文档中的方法

    2022-08-13 19:15:30
  • 学习python (1)

    2022-12-10 12:59:18
  • Python2/3中urllib库的一些常见用法

    2023-11-05 00:24:04
  • 详解Django中views数据查询使用locals()函数进行优化

    2021-01-21 00:53:13
  • Python pip配置国内源的方法

    2021-02-18 14:53:55
  • 利用MySQL空间函数实现位置打卡的完整步骤

    2024-01-28 11:23:32
  • asp之家 网络编程 m.aspxhome.com