Generate html| Generate HTML
There are already a lot of HTML generated news systems, but are all used templates, this function implementation of the ASP page generated HTML code saved into an HTML file, so there is no need to change the original page can easily complete a generation of HTML news system. ^_^
Because the code is relatively short, there is no comment here
<%
' When the target page contains the file that is the #include page, there is response. End () There is a problem with this procedure
' NOTE: This file must be placed in the same directory as the file that the filename points to
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*\-\-\>"
Todo
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)
Todo
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 (get_exe_code (filename), "Hughchiu_rtcode = hughchiu_rtcode&" "" "" ", &vbcrlf," "), "<%", "" "),"%\> "," "")
' Response. Write (Code)
Execute (Code)
' Response. Write (Hughchiu_rtcode)
asp2html = Hughchiu_rtcode
End Function
%>
Use Example:
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
I hope this function is a bit of use to everyone, because the level is limited, the wrong place please point out, and hope to be improved.