28,391
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<table width="350" border="0" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td width="80" bgcolor="#F3F3F3">编号</td>
<td bgcolor="#F3F3F3">标题</td>
</tr>
{$NewsCirculationStart$}
<tr>
<td width="80" bgcolor="#FFFFFF">{$NewsNumber$}</td>
<td bgcolor="#FFFFFF">{$NewsTitle$}</td>
</tr>
{$NewsCirculationEnd$}
</table>
</body>
</html>
<%
function ReadFromTextFile (FileUrl,CharSet)
dim str
set stm=server.CreateObject("adodb.stream")
stm.Type=2 '以本模式读取
stm.mode=3
stm.charset=CharSet
stm.open
stm.loadfromfile server.MapPath(FileUrl)
str=stm.readtext
stm.Close
set stm=nothing
ReadFromTextFile=str
end function
Sub WriteToTextFile (FileUrl,byval Str,CharSet)
set stm=server.CreateObject("adodb.stream")
stm.Type=2 '以本模式读取
stm.mode=3
stm.charset=CharSet
stm.open
stm.WriteText str
stm.SaveToFile server.MapPath(FileUrl),2
stm.flush
stm.Close
set stm=nothing
end Sub
'以上函数从网上搜的
'-----------------------------------------------------------------------
'函数:GetBetweenString
'作用:在字符串SStr中获取Str_1到Str_2之间的字符串
function GetBetweenString(SStr,Str_1,Str_2)
Dim CenterStr,RightStr
RightStr =right(SStr,len(SStr)-instr(SStr,Str_1)-len(Str_1)+1)
CenterStr =left(RightStr,instr(RightStr,Str_2)-1)
GetBetweenString=CenterStr
end function
Dim TemplateStr,Str1,Str2,Str3,Str4,Str5,PrintStr
TemplateStr=ReadFromTextFile ("template.html","UTF-8")
Str1=left(TemplateStr,instr(TemplateStr,"{$NewsCirculationStart$}")-1)
Str2=GetBetweenString(TemplateStr,"{$NewsCirculationStart$}","{$NewsNumber$}")
Str3=GetBetweenString(TemplateStr,"{$NewsNumber$}","{$NewsTitle$}")
Str4=GetBetweenString(TemplateStr,"{$NewsTitle$}","{$NewsCirculationEnd$}")
Str5=right(TemplateStr,len(TemplateStr)-instr(TemplateStr,"{$NewsCirculationEnd$}")-len("{$NewsCirculationEnd$}")+1)
'这里可以换成从数据库中读取的内容
PrintStr=Str1
for i=1 to 10
PrintStr=PrintStr&Str2&i&Str3&"这里是新闻标题["&i&"]"&Str4
next
PrintStr=PrintStr&Str5
call WriteToTextFile ("test.html",PrintStr,"UTF-8")
response.Write("<a href=""test.html"" target=""_blank"">查看文件</a>")
%>