日期:2011-09-17  浏览次数:20919 次

以下是程序源代码:
<% 
dim fname,fso,fout,htmlcode 
dim htmlbody,htmlbody1,page_n 
htmlbody=request.form("body") 
page_n=len(htmlbody)-len(replace(htmlbody,"$","")) 
’生成文件名的函数 
function makefilename(fname) 
fname = fname 
fname = replace(fname,"-","") 
fname = replace(fname," ","")  
fname = replace(fname,":","") 
fname = replace(fname,"PM","") 
fname = replace(fname,"AM","") 
fname = replace(fname,"上午","") 
fname = replace(fname,"下午","") 
makefilename=fname 
end function 
if request.querystring("action")="add" then 
for i=0 to page_n 
fname=makefilename(now()) 
if i=0 then 
ppage=0 
else 
ppage=i-1 
end if 
if i=0 and page_n>i then 
npage=i+1 
else 
npage=page_n 
end if 
shtml=split(htmlbody,"$")(i) & vbcrlf 
shtml=shtml&"<br><a href="""&fname&"_"&ppage&".html"">上一页</a> <a href="""&fname&"_"&npage&".html"">下一页</a>" 
Set fso = Server.CreateObject("Scripting.FileSystemObject") 
Set fout = fso.CreateTextFile(Server.MapPath(fname&"_"&i&".html")) 
fout.WriteLine shtml 
fout.close 
next 
response.write"<SCRIPT language=JavaScript>alert(’成功生成"&page_n+1&"个HTML页’);this.location.href=’javascript:history.back();’</SCRIPT>" 
end if 
%> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>爱易学习网_超长文件分页并生成HTML文件简单示例</title> 
</head> 
<body> 
<form name="form1" method="post" action="?action=add"> 
文章内容: 
<br> 
<textarea name="body" cols="60" rows="8"> 
第一页内容 

第二页内容 

第三页内容</textarea> 
<br> 
<input type="submit" name="Submit" value="提交"> 
</form> 
</body> 
</html>