长文章内容的分页函数的修改

在网络上看到一个针对内容比较长的文章自动分页的函数,拿过来用的时候感觉有点小问题,做了如下修改,方便日后调用

调用方式

ContentPagination(文章内容,传递过来的参数)

 

如 : <%=ContentPagination(body,"?aid=<%=request("aid")%>")%>

 

<%
Const maxPagesize=800    '设置分页字数

Function InsertPageBreak(strText)
 Dim strPagebreak,s,ss
 Dim i,IsCount,c,iCount,strTemp,Temp_String,Temp_Array
 strPagebreak="[hiweb_break]"
 s=strText
 If Len(s)<maxPagesize Then
  InsertPageBreak=s
 End If
 s=Replace(s, strPagebreak, "")
 s=Replace(s, "&nbsp;", "<&nbsp;>")
 s=Replace(s, "&gt;", "<&gt;>")
 s=Replace(s, "&lt;", "<&lt;>")
 s=Replace(s, "&quot;", "<&quot;>")
 s=Replace(s, "&#39;", "<&#39;>")
 If s<>"" and maxPagesize<>0 and InStr(1,s,strPagebreak)=0 then
  IsCount=True
  Temp_String=""
  For i= 1 To Len(s)
   c=Mid(s,i,1)
   If c="<" Then
    IsCount=False
   ElseIf c=">" Then
    IsCount=True
   Else
    If IsCount=True Then
     If Abs(Asc(c))>255 Then
      iCount=iCount+2
     Else
      iCount=iCount+1
     End If
     If iCount>=maxPagesize And i<Len(s) Then
      strTemp=Left(s,i)
      If CheckPagination(strTemp,"table|a|b>|i>|strong|div|span") then
       Temp_String=Temp_String & Trim(CStr(i)) & ","
       iCount=0
      End If
     End If
    End If
   End If 
  Next
  If Len(Temp_String)>1 Then Temp_String=Left(Temp_String,Len(Temp_String)-1)
  Temp_Array=Split(Temp_String,",")
  For i = UBound(Temp_Array) To LBound(Temp_Array) Step -1
   ss = Mid(s,Temp_Array(i)+1)
   If Len(ss) > 380 Then
    s=Left(s,Temp_Array(i)) & strPagebreak & ss
   Else
    s=Left(s,Temp_Array(i)) & ss
   End If
  Next
 End If
 s=Replace(s, "<&nbsp;>", "&nbsp;")
 s=Replace(s, "<&gt;>", "&gt;")
 s=Replace(s, "<&lt;>", "&lt;")
 s=Replace(s, "<&quot;>", "&quot;")
 s=Replace(s, "<&#39;>", "&#39;")
 InsertPageBreak=s
End Function

Function CheckPagination(strTemp,strFind)
 Dim i,n,m_ingBeginNum,m_intEndNum
 Dim m_strBegin,m_strEnd,FindArray
 strTemp=LCase(strTemp)
 strFind=LCase(strFind)
 If strTemp<>"" and strFind<>"" then
  FindArray=split(strFind,"|")
  For i = 0 to Ubound(FindArray)
   m_strBegin="<"&FindArray(i)
   m_strEnd  ="</"&FindArray(i)
   n=0
   do while instr(n+1,strTemp,m_strBegin)<>0
    n=instr(n+1,strTemp,m_strBegin)
    m_ingBeginNum=m_ingBeginNum+1
   Loop
   n=0
   do while instr(n+1,strTemp,m_strEnd)<>0
    n=instr(n+1,strTemp,m_strEnd)
    m_intEndNum=m_intEndNum+1
   Loop
   If m_intEndNum=m_ingBeginNum then
    CheckPagination=True
   Else
    CheckPagination=False
    Exit Function
   End If
  Next
 Else
  CheckPagination=False
 End If
End Function

Function ContentPagination(hiwebstr,urlc)
 Dim ContentLen, maxperpage, Paginate
 Dim arrContent, strContent, i
 Dim m_strFileUrl,m_strFileExt,ArticleID
 'ArticleID=Request.QueryString("ID")
 strContent = InsertPageBreak(hiwebstr)
 ContentLen = Len(strContent)
 CurrentPage=Request.QueryString("Page")
 If CurrentPage="" Then CurrentPage=0
 If InStr(strContent, "[hiweb_break]") <= 0 Then
  ArticleContent = "<div id=""NewsContentLabel"" class=""NewsContent"">" & strContent & "</div><div id=""Message"" class=""Message""></div>"
 Else
  arrContent = Split(strContent, "[hiweb_break]")
  Paginate = UBound(arrContent) + 1
  If CurrentPage = 0 Then
   CurrentPage = 1
  Else
   CurrentPage = CLng(CurrentPage)
  End If
  If CurrentPage < 1 Then CurrentPage = 1
  If CurrentPage > Paginate Then CurrentPage = Paginate
  strContent = "<div id=""NewsContentLabel"" class=""NewsContent"">"& arrContent(CurrentPage - 1)

  ArticleContent = ArticleContent & strContent
  If UserArticle = True Then
   ArticleContent = ArticleContent & "</p></div><div id=""Message"" class=""Message""></div><p align=""center""><b>"
  Else
   ArticleContent = ArticleContent & "</p></div><p align=""center""><b>"
  End If
  If IsURLRewrite Then
   'm_strFileUrl = ArticleID & "_"
   m_strFileUrl = urlc
  Else
   m_strFileExt = ""
   'm_strFileUrl = "?id=" & ArticleID & "&Page="
   m_strFileUrl = urlc & "&Page="
  End If
  If CurrentPage > 1 Then
   If IsURLRewrite And (CurrentPage-1) = 1 Then
    ArticleContent = ArticleContent & "<a href="""& ArticleID & m_strFileExt & """>上一页</a>&nbsp;&nbsp;"
   Else
    ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & CurrentPage - 1 & m_strFileExt & """>上一页</a>&nbsp;&nbsp;"
   End If
  End If
  For i = 1 To Paginate
   If i = CurrentPage Then
    ArticleContent = ArticleContent & "<font color=""red"">[" & CStr(i) & "]</font>&nbsp;"
   Else
    If IsURLRewrite And i = 1 Then
     ArticleContent = ArticleContent & "<a href="""& ArticleID & m_strFileExt & """>[" & i & "]</a>&nbsp;"
    Else
     ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & i & m_strFileExt & """>[" & i & "]</a>&nbsp;"
    End if
   End If
  Next
  If CurrentPage < Paginate Then
   ArticleContent = ArticleContent & "&nbsp;<a href="""& m_strFileUrl & CurrentPage + 1 & m_strFileExt & """>下一页</a>"
  End If
  ArticleContent = ArticleContent & "</b></p>"
 End If
 Response.Write(ArticleContent)
End Function
%> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值