ASP一个生成html的新方法

生成html|生成html

目前已经有很多生成html的新闻系统,但是都是用的模板,本函数实现把asp页面产生的html代码保存成为一个html文件,这样就没有必要改动原来的页面就可以轻松完成一个生成html的新闻系统了。^_^

由于代码比较短,这里就不进行注释了

<%
'当目标页面的包含文件即#include的页面里边存在response.End()的时候本程序有问题
'注意:本文件一定要放在filename指向的文件的同一目录下
dim hughchiu_rtcode
Function get_exe_code(filename)
 dim execode
 dim tmp_str
 Dim re,re1,content,fso,f,aspStart,aspEnd
 dim ms,m
 execode = ""
 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.ignorecase = true
 re.global = true
 re.pattern = "\<\%\@[^\%]+\%\>"
 content = re.replace(content,"")
 
 re.global = false
 re.pattern = "\<\!\-\-\s*\#include\s*file\s*=\s*\""([^\""]+)\""\s*\-\-\>"
 do
 set ms = re.execute(content)
if ms.count<>0 then
set m = ms(0)
tmp_str = get_exe_code(m.submatches(0))
content = re.replace(content, tmp_str)
else
exit do
end if
 loop
 set m = nothing
 set ms = nothing
 
 re.pattern="^\s*="
 aspEnd=1
 aspStart=inStr(aspEnd,content,"<%")+2
 
 set re1=new RegExp
 re1.ignorecase = true
 re1.global = false
 re1.pattern = "response\.Write(.+)"
 
 do while aspStart>aspEnd+1
  execode = execode&vbcrlf&" hughchiu_rtcode = hughchiu_rtcode&"""&replace( replace(Mid(content,aspEnd,aspStart-aspEnd-2),"""",""""""), vbcrlf, """&vbcrlf&""")&""""&vbcrlf
  aspEnd=inStr(aspStart,content,"%\>")+2
  tmp_str = Mid(content,aspStart,aspEnd-aspStart-2)
 
do
set ms = re1.execute(tmp_str)
if ms.count<>0 then
set m = ms(0)
tmp_str = re1.replace(tmp_str, " hughchiu_rtcode = hughchiu_rtcode&"&m.submatches(0))
else
exit do
end if
loop
 
  set m = nothing
  set ms = nothing
 
  execode = execode& re.replace(tmp_str,"hughchiu_rtcode = hughchiu_rtcode&")

  aspStart=inStr(aspEnd,content,"<%")+2
 loop
 
 set re1 = nothing
 set re=nothing
 
 execode = execode&vbcrlf&" hughchiu_rtcode = hughchiu_rtcode&"""&replace( replace(Mid(content,aspEnd), """", """"""), vbcrlf, """&vbcrlf&""" )&""""&vbcrlf
 get_exe_code = "<%"&execode&"%\>"
End Function

function asp2html(filename)
dim code
code = replace( replace( replace( get_exe_code(filename), "hughchiu_rtcode = hughchiu_rtcode&"""""&vbcrlf, "" ), "<%", "" ), "%\>", "" )
'response.Write(code)
execute(code)
'response.Write( hughchiu_rtcode )
asp2html = hughchiu_rtcode
end function
%>

使用范例:
set fso=CreateObject("Scripting.FileSystemObject")
set f=fso.CreateTextFile( server.mappath( "youpage.htm" ), true )
f.WriteLine( asp2html("youpage.asp") )
f.close
set f = nothing
set fso = nothing

希望这个函数对大家有点用,由于水平有限,有错的地方请大家指出,并希望能加以改进。

时间: 2024-09-08 11:47:16

ASP一个生成html的新方法的相关文章

一个生成html的新方法

  使用范例: set fso=CreateObject("Scripting.FileSystemObject") set f=fso.CreateTextFile( server.mappath( "" ), true ) f.WriteLine( asp2html("youpage.asp") ) f.close set f = nothing set fso = nothing 希望这个函数对大家有点用,由于水平有限,有错的地方请大家指出

ASP.NET生成图形验证码的方法详解_实用技巧

本文实例讲述了ASP.NET生成图形验证码的方法.分享给大家供大家参考,具体如下: 通常生成一个图形验证码主要 有3个步骤: (1)随机产生一个长度为N的随机字符串,N的值可由开发可由开发人员自行设置.该字符串可以包含数字.字母等. (2)将随机生成的字符串创建成图片,并显示. (3)保存验证码. 新建一个页面为default.aspx,  放置一个TextBox控件和一个Image控件,TextBox控件用于输入生成的字符串,Image控件用于显示字符串,它的图片就为生成的图形验证码image

一个用ASP生成html的新方法

目前已经有很多生成html的新闻系统,但是都是用的模板,本函数实现把asp页面产生的html代码保存成为一个html文件,这样就没有必要改动原来的页面就可以轻松完成一个生成html的新闻系统了.^_^由于代码比较短,这里就不进行注释了 <%'当目标页面的包含文件即#include的页面里边存在response.End()的时候本程序有问题'注意:本文件一定要放在filename指向的文件的同一目录下dim hughchiu_rtcodeFunction get_exe_code(filename

ASP生成html的新方法

已经有很多生成html的新闻系统,但是都是用的模板,本函数实现把asp页面产生的html代码保存成为一个html文件,这样就没有必要改动原来的页面就可以轻松完成一个生成html的新闻系统了.^_^ 由于代码比较短,这里就不进行注释了 以下为引用的内容: <% '当目标页面的包含文件即#include的页面里边存在response.End()的时候本程序有问题 '注意:本文件一定要放在20041227111723.htm指向的文件的同一目录下 dim hughchiu_rtcode Functio

ASP.NET生成静态网页的方法

asp.net|静态|网页 环境:Microsoft .NET Framework SDK v1.1OS:Windows Server 2003 中文版ASP.Net生成静态HTML页在Asp中实现的生成静态页用到的FileSystemObject对象!在.Net中涉及此类操作的是System.IO以下是程序代码 注:此代码非原创!参考别人代码Code://生成HTML页public static bool WriteFile(string strText,string strContent,s

ASP生成html的新方法_应用技巧

由于代码比较短,这里就不进行注释了  复制代码 代码如下: <% '当目标页面的包含文件即#include的页面里边存在response.End()的时候本程序有问题 '注意:本文件一定要放在20041227111723.htm指向的文件的同一目录下 dim hughchiu_rtcode Function get_exe_code(20041227111723.htm) dim execode dim tmp_str Dim re,re1,content,fso,f,aspStart,aspE

asp.net生成html页面的方法

1. 可以建立非常复杂的页面,利用包含js文件的方法,在js文件内加入document.write()方法可以在所有页面内加入如页面头,广告等内容. 2. 静态html文件利用MS Windows2000的Index Server可以建立全文搜索引擎,利用asp教程.net可以以DataTable的方式得到搜索结果.而Win2000的Index服务无法查找xml文件的内容.假如包括了数据库教程搜索与Index索引双重查找,那么此搜索功能将非常强盛. 3. 节省服务器的负荷,哀求一个静态的html

技巧实例:ASP.NET生成静态页面实现方法

asp.net|技巧|静态|页面 <!--Main.Aspx--> <%@ page language="C#" %> <%@ import namespace=System.IO %> <script runat="server"> protected override void OnInit (EventArgs e) { int id; try { id = int.Parse (Request.QueryStr

不用模板只用ASP+FSO生成静态HTML页的一个方法_应用技巧

不用模板,只用ASP+FSO生成静态HTML页的一个方法(对于内容密集型页面特别适用)  转载请注明:转自http://goaler.xicp.net FSO生成静态HTML文件的时候替换模板标签一直是一个很麻烦的问题,至少我是这么认为的,还要别外做一个模板,麻烦!,我今天看见有一个方法可以解决这个问题 如一个正常的index.asp页面,并且用ASP代码调出数据库中的内容,另建一个makehtml.asp的页面,加入一个textarea域,假设为name="body",将index.