2009年11月17日 星期二 00:20 A.M.共有两种办法。第一种方法使用mid函数,优点绝对准确,说100字换页就100字换页,缺点遇到如图片的代码<img src="http://www.baidu.com/img/baidu_logo.gif" width="120">之类的可能在http://的时候就分页了,导致图片显示不全。 <% page = request.querystring("page") if page="" then page=1 end if '文章正文部分 txt = "abcdefghijklmnopqrstuvwxyz"'定义10个字符翻一页 txtlen = 10 '显示正文 response.write mid(txt,(page-1)*txtlen+1,txtlen)&"<br /><br />" '计算总页数 if len(txt) mod txtlen <> 0 then '余数不为0,则余数加1,否则整除 allpage = int(len(txt)/txtlen)+1 else allpage = int(len(txt)/txtlen) end if for i=1 to allpage response.write "<a href=""?page="&i&""">第"&i&"页</a> " next %>第二种方法使用split函数,利用特殊的标签来分割字符串,这种比效智能,可以根据实际显示的需要来分页,原理跟mid差不多 <% page1 = request.querystring("page1") if page1 = "" then page1=1 end if '文章正文部分 txt1 = "abcdef分割符ghij分割符klmnopqr分割符stuvwxy分割符z" '利用split得出共有多少页 allpage1 = split(txt1,"分割符") '显示正文 response.write allpage1(page1-1)&"<br /><br />" for i=1 to ubound(allpage1)+1 response.write "<a href=""?page1="&i&""">第"&i&"页</a> " next %>
对文章进行xml解析,标签不算长度,当检查长度满足时候,获取前面的未结束标签,然后再这里插入标签未一个标签头,具体代码,自己动手~~免费的午餐时很少的~
整个div,固定高度,隐藏scroll,点击分页的链接,只负责上下移动scroll.
<%
page = request.querystring("page")
if page="" then
page=1
end if
'文章正文部分
txt = "abcdefghijklmnopqrstuvwxyz"'定义10个字符翻一页
txtlen = 10
'显示正文
response.write mid(txt,(page-1)*txtlen+1,txtlen)&"<br /><br />"
'计算总页数
if len(txt) mod txtlen <> 0 then '余数不为0,则余数加1,否则整除
allpage = int(len(txt)/txtlen)+1
else
allpage = int(len(txt)/txtlen)
end if
for i=1 to allpage
response.write "<a href=""?page="&i&""">第"&i&"页</a> "
next
%>第二种方法使用split函数,利用特殊的标签来分割字符串,这种比效智能,可以根据实际显示的需要来分页,原理跟mid差不多
<%
page1 = request.querystring("page1")
if page1 = "" then
page1=1
end if
'文章正文部分
txt1 = "abcdef分割符ghij分割符klmnopqr分割符stuvwxy分割符z"
'利用split得出共有多少页
allpage1 = split(txt1,"分割符")
'显示正文
response.write allpage1(page1-1)&"<br /><br />"
for i=1 to ubound(allpage1)+1
response.write "<a href=""?page1="&i&""">第"&i&"页</a> "
next
%>
PHP code
//一段很长的代码后,新闻的内容读出来了。//把内容进切割。
$info_arr = preg_split("/<hr[^>]*>/i",$info);//遍历每个内部分页内容.
foreach($info_arr as $key=>$val) {
//生成新内的目录.
//例如 原新闻为 news/2355.html 则第二篇为 news/2355_2.html 第n篇为 news/2355_n.html
if($key == 0) {$new_dest_path = $dest_path;}
else {
$new_dest_path_arr = pathinfo($new_dest_path);
$dest_key = $key +1;
$id_tail = str_pad($id, 9, "0", STR_PAD_LEFT);
$id_tail = substr($id_tail,6,3);
$new_dest_path = $new_dest_path_arr["dirname"]."/".$id_tail."_".$dest_key.".html";
} //得到每个页面的分列条 通常是上一页 1 2 3 4 5 下一页 最后页
$data["innerpage"] = $this->get_page_link($id,sizeof($info_arr),$key); //
}
//附,得到分页的数据。
function get_page_link($id,$size,$cur)
{
if($cur != 0 ){
$page_info = "<div class = 'innerpage'><a href = '".CS_get_newsurl_byid($id,0)."'>首页</a>";
}else {
$page_info = "<div class = 'innerpage'><span>首页</span>";
}
for($key = 0;$key < $size;$key++) {
$dest_key = $key +1;
if($cur == $key)
{$page_info .= "<span class = 'curpage'>$dest_key</span>"; continue;}
if($dest_key == 1) $page_info .= "<a href = '".CS_get_newsurl_byid($id,0)."'>1</a>";
else $page_info .= "<a href = '".CS_get_newsurl_byid($id,$key+1)."'>$dest_key</a>";
}
if($cur != $size-1 ){
$page_info .= "<a href = '".CS_get_newsurl_byid($id,$size)."'>末页</a></div>";
}else{
$page_info .= "<span>末页</span></div>";
}
return $page_info;
}
貼上来,希望对楼主有用。
或者js,但是js会全部读取出来,只是不显示而已。
下面是个简单的例子。你可以复制然后运行一下就行了。
<?php
$content = 'asdasdasdasd<div style="page-break-after: always"><span style="display: none"> </span></div>ccccccccccsdasdas';
$G_cfg = '<div style="page-break-after: always"><span style="display: none"> </span></div>'; // 分页符
$arr_content = explode($G_cfg, $content); // 按分页符把文章内容切成数组
$page = @(int)$_GET['page']; // GET传递页码page参数
$pamount= sizeof($arr_content); // 所切数组的大小
if($page <= 0) $page = 1; // 当$page不存在时,为首页
if($page > $pamount && $pamount > 0) $page = $pamount; // 当$page大于数组大小值时,为尾页
$content = $arr_content[$page-1];
$strpage = '';
if($pamount > 1) {
for($i=0;$i<$pamount;$i++) {
if($i+1 == $page) {
$strpage .= '[<span style="color:red">' . ($i+1) . '</span>] | ';
} else {
$strpage .= '[<a href="display.php?id=' . $id . '&page=' . ($i+1) . '" title="' . $article_title . ' 第' . ($i+1) . '页" target="_self">' . ($i+1) . '</a>] | ';
}
}
$strpage = substr($strpage, 0, strlen($strpage)-3);
}
echo $content;
echo "<br />";
echo $strpage;
?>