超长字符的智能分页-支持HTML 

大概在九九年做游戏网站的时候,就对文章的发布感到麻烦,不过那会儿玩ASP不精。只是将就用着。在遇到长文件 10000 字时网页就是一大片长了。

去年,做一个通用的文章与新闻管理系统时,曾写了一段代码,用来分离。现在贴出来。

要说明的是:

我的文章 录入界面是基于WEB的HEMLEDITOR,就像这里的ABC代码差不多。所以实际提交的是HTML格式的文 本。

对HTML做了相应的处理,不会由HTML代码中切开。

这里另一位兄弟曾发表过一个,原理一样,不过我没仔细看过,不知有啥不同。

代码如下:
--------------------------------------
''Request Form Item
I_Forder = Request.Form ("I_Folder")
I_Topic = Request.Form ("I_Topic")
I_Title = htmlencode(Request.Form ("I_Title"))
I_Body = Request.Form ("body")
I_Source = Request.Form ("I_Source")
I_Keyword= htmlencode(Request.Form ("I_Keyword"))
I_ISHOT = request.form("ishot")
if i_ishot = "" then i_ishot="N"
i_ispic = request.form("ispic")
if i_ispic = "" then i_ispic ="N"
i_pic = request.form("InsertImage")
i_body = replace(i_body,"contentEditable=true","contentEditable=false")

''Check Input
''......

''Get Pages ,B = Body
B_Len = Len(I_Body)
B_Pages = 1
''T = Temp
T_Loop = true

Do While T_Loop ''这里loop多次,每4000分一页,算出页码并加入库。
If B_Len > 4000 then
N_Body = Left(I_Body,4000) ''N = New
''If "

 1<p" "="" in="" n_body,else="">" in N_Body   
 2If Instrrev(N_Body,"<p")> 0 and (Len(N_Body) - Instrrev(N_Body,"<p"))< ")="" 400="" else="" if="" instrrev(n_body,"="" n_body='Left(N_Body,InstrRev(N_Body,"&lt;P")-1)' then=""> 0 and (Len(N_Body) - Instrrev(N_Body," "))&lt; 400 then   
 3N_Body = Left(N_Body,InstrRev(N_Body," ")-1)   
 4Else If Instrrev(N_Body,"。") &gt; 0 and (Len(N_Body) - Instrrev(N_Body,"。"))&lt; 400 then   
 5N_Body = Left(N_Body,InstrRev(N_Body,"。"))   
 6Else If Instrrev(N_Body,";") &gt; 0 and (Len(N_Body) - Instrrev(N_Body,";"))&lt; 400 then   
 7N_Body = Left(N_Body,InstrRev(N_Body,";"))   
 8else if Instrrev(N_Body,",") &gt; 0 and (Len(N_Body) - Instrrev(N_Body,","))&lt; 400 then   
 9N_Body = Left(N_Body,InstrRev(N_Body,","))   
10else if Instrrev(N_Body,".") &gt; 0 and (Len(N_Body) - Instrrev(N_Body,"."))&lt; 400 then   
11N_Body = Left(N_Body,InstrRev(N_Body,"."))   
12end if   
13end if   
14End If   
15End If   
16end if   
17End if   
18  
19N_Len = Len(N_Body)   
20I_Body = Mid(I_Body,N_Len+1)   
21B_Len = Len(I_Body)   
22  
23Else   
24N_Body = I_Body   
25T_Loop = false   
26End If   
27  
28  
29''Add to database   
30Exec_prc_Content_Ins I_Forder,I_Topic,I_Title,I_Source,N_Body,i_ispic,i_pic,i_ishot,I_Keyword,B_Pages   
31  
32''这里一个function,你可以自己处理,反正结果有两个,一个是body,一个是b_pages,就是页码。   
33  
34  
35B_Pages = B_Pages + 1   
36  
37Loop   
38  
39  
40%&gt;   
41  
42<html>
43<head>
44<meta content="Microsoft FrontPage 5.0" name="GENERATOR"/>
45<meta content="FrontPage.Editor.Document" name="ProgId"/>
46<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
47<title>新建网页 1</title>
48<link href="../CSS/default.css" rel="stylesheet" type="text/css"/>
49</head>
50<body>
51<div align="center">
52<center>
53<table border="1" bordercolor="#000000" cellpadding="0" cellspacing="0" height="128" style="border-collapse: collapse" width="300"><tr>
54<td bgcolor="#DEDBD6" height="31">   
55录入成功</td></tr><tr><td height="96">
56<p align="center">此文章共分```
57=B_Pages-1
58```页   
59</p></td></tr></table>
60</center>
61</div>
62<script>   
63top.main_top.location.reload();   
64</script>
65</body></html></p"))<></p")></p">
Published At
Categories with Web编程
Tagged with
comments powered by Disqus