利用统计文章字数,然后达到一定字数就截断输出,但是分页的内容就会在莫名其妙的地方截断,不是很友好。
很简单,在要截断的地方附近找下面的符号:
;’”?。!;".!
如果后面存在<p>或<br>就分页。主要是要研究文章的格式。
<%
if request.servervariables("content_length") > 0 then
content = request.form("textarea1")
pagelength = 1000 每页字数
clength = len(content)
pagecount = int(clength/pagelength) + 1 计算页数
dim pagearray
redim pagearray(pagecount)
seperator = array(chr(13),chr(10),"。","!","?",";",",","”","’") 分隔符
pagearray(0) = 0
pos = 0
for j=0 to ubound(seperator)
pos = instr(pagearray(i)+900,content,seperator(j)) pagearray(i)+900 附近位置是100字,1-999可调
while pos > 0 and pos < (i+1)*pagelength and pos > i*pagelength
pagearray(i) = pos
pos = instr(pos+pagelength,content,seperator(j))
wend
if pagearray(i) > 0 then
response.write "0:i¦ "&pagearray(i)&"<br>"&j&":j"&seperator(j)&"<br>"
j = j + ubound(seperator) + 1
end if
next
for i=1 to pagecount-1
pagearray(i) = 0
pos = 0
for j=0 to ubound(seperator)
pos = instr(pagearray(i-1)+950,content,seperator(j))
while pos > 0 and pos < (i+1)*pagelength and pos > i*pagelength
pagearray(i) = pos
pos = instr(pos+pagelength,content,seperator(j))
wend
if pagearray(i) > 0 then
response.write i&":i¦ "&pagearray(i)&"<br>"&j&":j"&seperator(j)&"<br>"
j = j + ubound(seperator) + 1
end if
next
next
output = mid(content,1,pagearray(0))
output = replace(output,chr(13),"<br>")
response.write "<br><br>第1段<br>"
response.write output
for i=1 to pagecount-2
output = mid(content,pagearray(i-1)+1,pagearray(i)-pagearray(i-1))
output = replace(output,chr(13),"<br>")
response.write "<br><br>第"&i+1&"段<br>"
response.write output
next
最后一段的输出就没写了
else
%>
<form action="" method=post id=form1 name=form1>
<textarea rows=70 cols=120 id=textarea1 name=textarea1>
</textarea>
<input type="submit" value="submit" id=submit1 name=submit1>
</form>
<%end if%>