模板页:
<div class="Box">
<h5>文章</h5>
<ul>
{$ArtList(10,50,11,"")}
</ul>
</div>
ASP页:
'==========================================================
'函数名:ReadtxtFiles
'函数作用:读取文件
'参数:Filename 文件路径
'==========================================================
Function ReadtxtFiles(FileName)
Dim fso, f1, ts, s,oFileName
Const ForReading = 1
oFileName = Server.MapPath(Filename)
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.OpenTextFile(oFileName, ForReading)
ReadtxtFiles = ts.ReadAll
ts.Close
End Function
'========================================
'函数名:CreateFile
'作 用:创建文件
'参 数:FileName -----文件名
' Content -----内容
'返回值:成功返回相对路径,否则返回、False
'========================================
Function CreateFile(FileName,Content)
On Error Resume Next
oFileName = FileName
Set FSO = Server.CreateObject("Scripting.FileSystemObject")
Set fd=FSO.Createtextfile(Server.MapPath(oFileName),True)
fd.writeline Content
If Err > 0 Then
Err.Clear
CreateFile = False
Else
CreateFile = FileName
End If
End Function
Function ReplaceParameter(Byval sContent)
Dim Matches,Match,TempValue,ArrayStr,DataStr
Dim regEx ' 建立变量。
Set regEx = New RegExp ' 建立正则表达式。
regEx.Pattern = patrn ' 设置模式。
regEx.IgnoreCase = False ' 设置是否区分字符大小写。
regEx.Global = True
regEx.Pattern = "{\$.[^{\$}]*}"
Set Matches = regEx.Execute(sContent)
For Each Match in Matches
TempValue = Match.Value
TempValue = Replace(TempValue,"{$","")
TempValue = Replace(TempValue,"}","")
TempValue = Replace(TempValue,"(",",")
TempValue = Replace(TempValue,")","")
TempValue = Replace(TempValue,Chr(34),"")
ArrayStr = Split(TempValue,",")
Select Case LCase(ArrayStr(0))
'Rem 文章部分
Case "ArtList"
DataStr = ArtList(ArrayStr(1),ArrayStr(2),ArrayStr(3),ArrayStr(4))
Case Else : DataStr = Match.Value
End Select
sContent = Replace(sContent,Match.Value,DataStr)
ArrayStr = Empty
DataStr = Empty
TempValue = Empty
Next
Set Matches = Nothing:Set regEx=Nothing
ReplaceParameter = sContent
End Function
'========================================= 文章
Function ArtList(Num,TxT,FDate,ClassId)
Dim oSQL,oRs,outStr
outStr = ""
oSQL = "Select Top "&Num&" Article_id,Article_title,Article_date,Article_count from Article Where 1 =1 "
If ClassId <> "" Then
oSQL = oSQL &" And cat_id = "&ClassId&""
End If
oSQL = oSQL &" order by Article_id desc"
Set oRs = Conn.Execute(oSQL)
If (oRs.EOF And oRs.BOF) Then
outStr = outStr &"<li>当前还没有添加文章!</li>" & vbCrLf
Else
ArrArt = oRs.GetRows()
For i = 0 To Ubound(ArrArt,2)
outStr = outStr &"<li><span>"&FormatDate(ArrArt(2,i),FDate)&"</span><a title=""文章标题:"&ArrArt(1,i)&"
发布时间:"&formatdate(ArrArt(2,i),2)&"
浏览次数:"&ArrArt(3,i)&""" href=""Article/ShowArticle.asp?id="&ArrArt(0,i)&""" target=""_blank"">"&gotTopic(ArrArt(1,i),TxT)&"</a></li>" & vbCrLf
Next
End If
Set oRs = Nothing
ArtList = outStr
End Function
我数据库里面是有数据的,及时没有也应该返回一个提示信息,最后执行:
<%
Dim outStr,oFileHtml
oFileHtml = ReadtxtFiles("TempLabe/Index.html")
outStr = ReplaceParameter(oFileHtml)
Call CreateFile("10.html",outStr)
%>
创建出来的:10.html
里面并没有提示。。不知道哪里错了。高手帮忙看啊。。
我只有42分。不好意思。只能发30分出来。。