熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP生成html的新方法

2013-11-13 10:39:24  來源: .NET編程 

  已經有很多生成html的新聞系統但是都是用的模板本函數實現把asp頁面產生的html代碼保存成為一個html文件這樣就沒有必要改動原來的頁面就可以輕松完成一個生成html的新聞系統了^_^
由於代碼比較短這裡就不進行注釋了

  以下為引用的內容
<%
當目標頁面的包含文件即#include的頁面裡邊存在responseEnd()的時候本程序有問題
注意本文件一定要放在htm指向的文件的同一目錄下
dim hughchiu_rtcode
Function get_exe_code(htm)
dim execode
dim tmp_str
Dim rerecontentfsofaspStartaspEnd
dim msm
execode = ""
set fso=CreateObject("ScriptingFileSystemObject")
set f=fsoOpenTextFile(servermappath(htm))
content=fReadAll
fclose
set f=nothing
set fso=nothing

  set re = new regexp
reignorecase = true
reglobal = true
repattern = "<%@[^%]+%>"
content = rereplace(content"")

  reglobal = false
repattern = "<!s*#includes*files*=s*""([^""]+)""s*>"
do
set ms = reexecute(content)
if mscount<> then
set m = ms()
tmp_str = get_exe_code(msubmatches())
content = rereplace(content tmp_str)
else
exit do
end if
loop
set m = nothing
set ms = nothing

  repattern="^s*="
aspEnd=
aspStart=inStr(aspEndcontent"<%")+

  set re=new RegExp
reignorecase = true
reglobal = false
repattern = "responseWrite(+)"

  do while aspStart>aspEnd+
execode = execode&vbcrlf&" hughchiu_rtcode = hughchiu_rtcode&"""&replace( replace(Mid(contentaspEndaspStartaspEnd)"""""""""") vbcrlf """&vbcrlf&""")&""""&vbcrlf
aspEnd=inStr(aspStartcontent"%>")+
tmp_str = Mid(contentaspStartaspEndaspStart)

  do
set ms = reexecute(tmp_str)
if mscount<> then
set m = ms()
tmp_str = rereplace(tmp_str " hughchiu_rtcode = hughchiu_rtcode&"&msubmatches())
else
exit do
end if
loop

  set m = nothing
set ms = nothing

  execode = execode& rereplace(tmp_str"hughchiu_rtcode = hughchiu_rtcode&")

  aspStart=inStr(aspEndcontent"<%")+
loop

  set re = nothing
set re=nothing

  execode = execode&vbcrlf&" hughchiu_rtcode = hughchiu_rtcode&"""&replace( replace(Mid(contentaspEnd) """" """""") vbcrlf """&vbcrlf&""" )&""""&vbcrlf
get_exe_code = "<%"&execode&"%>"
End Function

  function asphtml(htm)
dim code
code = replace( replace( replace( get_exe_code(htm) "hughchiu_rtcode = hughchiu_rtcode&"""""&vbcrlf "" ) "<%" "" ) "%>" "" )
responseWrite(code)
execute(code)
responseWrite( hughchiu_rtcode )
asphtml = hughchiu_rtcode
end function
%> 
 

  使用范例

  以下為引用的內容

  
set fso=CreateObject("ScriptingFileSystemObject")
  set f=fsoCreateTextFile( servermappath( "youpagehtm" ) true )
  fWriteLine( asphtml("youpageasp") )
  fclose
  set f = nothing
  set fso = nothing


From:http://tw.wingwit.com/Article/program/net/201311/14236.html
    推薦文章
    Copyright © 2005-2013 電腦知識網 Computer Knowledge   All rights reserved.