A new method for generating HTML

xiaoxiao2021-03-06  38

There are already many news systems that generate HTML, but they are all templates. This function implements the HTML code generated by the ASP page into an HTML file, so there is no need to change the original page to easily complete a news that generates HTML The system is.

^ _ ^ Since the code is short, it is not commented here. When the target page contains the file 即 # # 即 即 # 即 r r r r r r r r 本 本 本 本 本 本 本 本 问题::::::::: the same filename directory file pointed dim hughchiu_rtcodeFunction 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 =" / "Do SET MS = Re.execute (content) IF Ms.count <> 0 THENSET M = MS (0) TMP_STR = GET_EXE_CODE (M.Submatches (0)) Content = Re.Replace (Content, TMP_STR) ElseExit Doend If Loop Set M = Nothing Set MS = Nothing Re.pattern = "^ / s * =" aspend = 1 aspstart = INSTAR (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 &" "" ) & "" "& vbcrf aspend = INSTR (aspstart, content,"% /> ") 2 TMP_STR = MID (Content, AsPstart, Aspend-AsPstart-2) DOSET MS = Re1.execute (TMP_STR) if ms.count <

> 0 thenset m = ms (0) tmp_str = re1.replace (tmp_str, "hughchiu_rtcode = hughchiu_rtcode &" & m.submatches (0)) elseexit doend ifloop 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," "" & vbcrf & "") & "" "" & vbrlf get_exe_code = "<%" & execode & "% />" end function

Function Asp2HTML (FileName) DIM Codecode = Replace (Replace (get_exe_code (filename), "hughchiu_rtcode = hughchiu_rtcode &" "" "& vbrlf," ")," <% ",", ","% /> "," ") 'response.write (code) Execute (code)' response.write (hughchiu_rtcode) ASP2HTML = hughchiu_rtcodeend function%>

Example of use: set fso = createObject ("scripting.filesystemObject") set f = fso.createtextfile (Server.MAppath ("Youpage.htm"), true) F.Writeline ("Youp2HTML (" Youpage.asp ")) F.Closset f = NothingSet FSO = Nothing

I hope this function is a bit used for everyone. Because of the limited level, if you have a wrong place, please point out, and hope to improve.

转载请注明原文地址:https://www.9cbs.com/read-76906.html

New Post(0)