代码
'ContentAutoPage.asp
'用法:<%=ContentPagination(文章内容)%>
const maxPagesize = 2000 '设置分页字数
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, " ", "< >")
s = replace(s, ">", "<>>")
s = replace(s, "<", "<<>")
s = replace(s, """, "<">")
s = replace(s, "'", "<'>")
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, "< >", " ")
s = replace(s, "<>>", ">")
s = replace(s, "<<>", "<")
s = replace(s, "<">", """)
s = replace(s, "<'>", "'")
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)
dim ContentLen, maxperpage, Paginate
dim arrContent, strContent, i
dim m_strFileUrl, m_strFileExt, ArticleID
ArticleID = Request.QueryString("Info_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"" >" & strContent & "</div><div id=""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"" >"& arrContent(CurrentPage - 1)
ArticleContent = ArticleContent & strContent
if UserArticle = True then
ArticleContent = ArticleContent & "</p></div><div id=""Message"" ></div><p align=""center"">"
else
ArticleContent = ArticleContent & "</p></div><p align=""center"">"
end if
if IsURLRewrite then
m_strFileUrl = ArticleID & "_"
else
m_strFileExt = ""
m_strFileUrl = "?Info_ID=" & ArticleID & "&Page="
end if
if CurrentPage > 1 then
if IsURLRewrite and (CurrentPage -1) = 1 then
ArticleContent = ArticleContent & "<a href="""& ArticleID & m_strFileExt & """>上一页</a> "
else
ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & CurrentPage - 1 & m_strFileExt & """>上一页</a> "
end if
end if
for i = 1 to Paginate
if i = CurrentPage then
ArticleContent = ArticleContent & "[" & cstr(i) & "] "
else
if IsURLRewrite and i = 1 then
ArticleContent = ArticleContent & "<a href="""& ArticleID & m_strFileExt & """>[" & i & "]</a> "
else
ArticleContent = ArticleContent & "<a href="""& m_strFileUrl & i & m_strFileExt & """>[" & i & "]</a> "
end if
end if
next
if CurrentPage < Paginate then
ArticleContent = ArticleContent & " <a href="""& m_strFileUrl & CurrentPage + 1 & m_strFileExt & """>下一页</a>"
end if
ArticleContent = ArticleContent & "</p>"
end if
Response.write(ArticleContent)
end function