我目前在开发一个小说的浏览功能,但是小说很长,一般在1000万字左右,小说里面还有图片,该小说的内容保存在数据库里。
在浏览小说的时候打算分页,比如浏览1000万的小说就分1000页,每页就1万字左右,但是因为小说里面有图片,导致按字数分的时候出现问题。
比如html <img src=aaaa.jpg>有可能就被截断了,<img src=a 在第一页,aaa.jpg> 在下一页,请问怎么解决这个问题,谢谢
培训新闻
- 绝对高端,开沅教育(大连)中心2009年首期P...
- 开沅教育(大连)中心--09年3月北京交通大学...
- .广州多迪php培训,年前最后一期优惠,大家快...
- 上海实战精英班二期开始报名了~~~~~
- 大连开沅教育09年LAMP首期“就业班”开始报名...
- 北京十一期实战精英班,正在热招中,速速报名...
- 大连开沅教育08年寒假lamp精品培训招生开始,...
- 北京PCTI-19期,正在热招中,年前报名有优惠...
热点专题
网站特别推荐
- 调查:长春地区计划开展PHP培训,长春地区的...
- 3月份研究生班提高项目开发能力
- 新年新规划 充电培训就业 就来PHPChina唐山培...
- 唐山培训中心“首期实战班”赠送联想双核笔记...
- LAMP兄弟连09年课程表
- 绝对高端,开沅教育(大连)中心2009年首期P...
- 2008.12.24李明老师"互联网时代的就业与...
- 上海实战精英班二期开始报名了~~~~~
- 开沅教育(大连)中心--09年3月北京交通大学...
- 北京十一期实战精英班,正在热招中,速速报名...
社区精华
- linuxroot吐血推荐花了一天时间写的强壮捕获各...
- PHPChina伯乐PHP程序员(1年)
- PHPChina伯乐北京高级的PHP程序员
- PHPChina伯乐浙江 高薪职位!
- PHPChina伯乐网站技术






最新回复
我现在就是用这个方法,感觉还行,不知是否适合你!!!
http://tidy.sourceforge.net/
http://tw2.php.net/tidy
QUOTE:
偶也是这么整的QUOTE:
补全应该怎么用了,谢谢不知道还有别的方案没有啊?
0-1000的字符搜索是否有> 如果有就多一位 截取 然后再截取 不过麻烦点
QUOTE:
不对,>可以是标签的开始,也可以是结束,所以不能判断。<a href='aaa.htm'>aaa</a>
这里要是以>,就会出问题,在前面就被截断了,链接字就不见了
那还是用标签补全吧 没弄过标签不全 弄完了 贴个代码看看
貌似比较复杂,楼主弄完了代码分享下。。。
个人觉得还是标签补全比较好些
'Version 1.2
'Author Turnip
'QQ 63842303
'Update 2008-6-21 3:21:15
' 使用实例:
'
' Dim strCnt
' strCnt = "<P>0<FONT face=Verdana>1<BR>2<BR>3<BR>4</FONT><table><tr><td></td></tr></table>5</P>6"
'
' Dim clsDoc,content,setpage
'
' Set clsDoc = new splitDoc
' clsDoc.sStr = str(0) 字符串
' clsDoc.pageSize = 1 第页显示的字符数(可选,默认为1000个字符)
' clsDoc.curPage = Request("docpage") 要显示的页码
' content = clsDoc.getStr() 截取后的内容
' setpage = clsDoc.showPage(para) 翻页
' Set clsDoc = Nothing
Class splitDoc
Private sRegExp '正则对象
Private arrLable '存放标签的数组
Private arrTotal '存放数据和空标签的数组
Private isInFst '标签是否在字符串的开始
Private isNeedSplit '是否需要分隔
Private isIncLabel '字符串是否含有标签
Private delimiter '分隔符
Public sStr '字符串
Public pageSize '每页显示的字数---默认为1000字
Public curPage '现在要显示的页码---默认为第一页
Private totalPage '共有几页
Public Function getStr()
Call chkNeedR
If isNeedSplit Then
Dim iLable, iTotal, tmpNum, curNum, startNum, endNum, startPos, lenTmp, strTmp
Call chkCurPage()
If Not isIncLabel Then '不含有标签,直接截取
startPos = pageSize * (curPage - 1) + 1
getStr = Mid(sStr, startPos, pageSize)
Else
curNum = 0
startNum = pageSize * (curPage - 1) + 1
endNum = pageSize * curPage
iLable = 0
Call getArrLable
Call getArrTotal
For iTotal = 0 To UBound(arrTotal)
lenTmp = Len(arrTotal(iTotal))
If lenTmp > 0 Then
If curNum < startNum Then
If curNum + lenTmp >= startNum Then
If curNum + lenTmp >= endNum Then
strTmp = strTmp & Mid(arrTotal(iTotal), startNum - curNum, endNum - startNum + 1)
strTmp = strTmp & joinArrLable(iLable)
Exit For
Else
strTmp = strTmp & Mid(arrTotal(iTotal), startNum - curNum)
curNum = curNum + lenTmp
End If
Else
curNum = curNum + lenTmp
End If
ElseIf curNum < endNum Then
If curNum + lenTmp <= endNum Then
strTmp = strTmp & arrTotal(iTotal)
curNum = curNum + lenTmp
Else
strTmp = strTmp & Mid(arrTotal(iTotal), 1, endNum - curNum)
strTmp = strTmp & joinArrLable(iLable)
Exit For
End If
Else
strTmp = strTmp & joinArrLable(iLable)
Exit For
End If
strTmp = strTmp & addALable(iLable)
Else
strTmp = strTmp & addALable(iLable)
End If
Next
getStr = TrimBlank(strTmp)
End If
Else
getStr = sStr
End If
End Function
Private Function joinArrLable(strtIndex)
Dim i
For i = strtIndex To UBound(arrLable)
joinArrLable = joinArrLable & arrLable(i)
Next
End Function
Private Sub chkCurPage()
If Not IsNumeric(curPage) Then
curPage=1
ElseIf CDbl(curPage)<1 Then
curPage = 1
ElseIf CDbl(curPage)>totalPage Then
curPage=totalPage
End If
End Sub
Private Function addALable(index)
If index <= UBound(arrLable) Then
addALable = arrLable(index)
index = index + 1
End If
End Function
Private Sub Class_Initialize()
Set sRegExp = New RegExp
sRegExp.Pattern = "<[^>]*>"
sRegExp.IgnoreCase = True
sRegExp.Global = True
pageSize = 1000
curPage = 1
delimiter = "$split"
End Sub
Private Function TrimBlank(ByVal str)
Dim arrPattern(2),i
arrPattern(0) = "<tr[^>]*>(<td[^>]*>\s*<\/td>)*<\/tr>"
arrPattern(1) = "<table[^>]*><\/table>"
arrPattern(2) = "<p[^>]*>(<\/?[^>]*>)*</p>"
For i=0 To UBound(arrPattern)
sRegExp.Pattern = arrPattern(i)
str = sRegExp.Replace(str, "")
Next
TrimBlank = str
End Function
Private Sub Class_Terminate()
Set sRegExp = Nothing
End Sub
Private Sub getArrLable()
Dim Match, Matches, RetStr, strTmp
strTmp = sStr
Set Matches = sRegExp.Execute(strTmp)
For Each Match In Matches
RetStr = RetStr & delimiter & Match.Value
Next
arrLable = Split(Mid(RetStr, Len(delimiter) + 1), delimiter)
End Sub
Private Sub getArrTotal()
Dim strTmp
strTmp = sStr
arrTotal = Split(sRegExp.Replace(strTmp, delimiter), delimiter)
End Sub
Private Sub chkNeedR()
On Error Resume Next
Dim strTmp, totalChr
strTmp = sStr
totalChr = Len(sRegExp.Replace(strTmp, ""))
If Len(strTmp) <= pageSize Or totalChr <= pageSize Then
totalPage = 1
isNeedSplit = False
Else
totalPage = Fix(totalChr / pageSize)
If (totalChr Mod pageSize) <> 0 Then totalPage = totalPage + 1
isNeedSplit = True
End If
isIncLabel = sRegExp.test(strTmp)
End Sub
Public Function showPage(para)
Dim arr,i,n
ReDim arr(totalPage)
For i = 1 To totalPage
If CStr(i) = CStr(curPage) Then
arr(n) = "<span style=""color:red;"">[" & i & "]</span> "
Else
arr(n) = "<a href='?docpage=" & i & para & "'>[" & i & "]</a> "
End If
n = n + 1
Next
If totalPage > 1 Then showPage = "<div class=""docpage"" style=""text-align:center;"">" & Join(arr, "") & "</div>"
End Function
End Class
%>
<a href=aaaa.jpg>sdfdsf</a>
前一页是:<a href=aa
后一页是:aa.jpg>sdfdsf</a>
结果前一页被补全成了:<a href=aa></a>
后面的aa.jpg不见了