Write HTML code to a file and generate an. HTML-formatted file
Write HTML code to a file and generate an. HTML-formatted file
<%
filename= "test.htm"
If Request ("Body") <> "" Then
Set fso = Server.CreateObject ("Scripting.FileSystemObject")
Set htmlwrite = FSO. CreateTextFile (Server.MapPath ("filename"))
Htmlwrite.write " Htmlwrite.write <body> output title: "Request.Form (" Title ")" <br/> Output body content: "Request.Form (" Body ")" </body> Htmlwrite.close
Set fout= Nothing
Set fso=nothing
End If
%>
<form name= "form" method= "POST" action= "" >
& Lt;input name= "title" value= "title" Size=26>
<br>
<textarea name= "Body" >Body</textarea>
<br>
<br>
<input type= "Submit" name= "submit" value= "Generate HTML" >
</form>< /p>
2, but according to the above method to generate HTML file is very inconvenient, the second approach is to use template technology to replace the value of special code in the template with a value accepted from the form or database field, complete the template function, and generate an HTML file for all the template code that is eventually replaced. This technique is used more, Most CMS uses this type of method.
Template.htm '//template file
<HTML>
<title> $title $ by aspid.cn</title>
<body>
$body $
</body>
<%
Dim Fso,htmlwrite
Dim Strtitle,strcontent,strout
'//Create File system objects
Set fso=server.createobject ("Scripting.FileSystemObject")
'//Open page template file, read template content
Set Htmlwrite=fso. OpenTextFile (Server.MapPath ("template.htm"))
Strout=f.readall
Htmlwrite.close
strtitle= "generated page title"
strcontent= "generated Web page content"
'//Replace the tag in the template with the real content
Strout=replace (Strout, "$title $", strtitle)
Strout=replace (Strout, "$body $", strcontent)
'//Create a static page to be generated
Set Htmlwrite=fso. CreateTextFile (Server.MapPath ("test.htm"), true)
'//write page content
Htmlwrite.writeline Strout
Htmlwrite.close
Response.Write "Generate static page success!" "
'//Release File system objects
Set htmlwrite=nothing
Set fso=nothing
%>