现在工作中需要用到分页程序因为新闻的内容太长,需要把每条新闻内容分页显示只做用新闻列表的分页,内容的分页真的不知道该怎么实现,请高人指点指点非常感谢!
解决方案 »
- netbeans6.9.1如何可视化编辑?
- 用php实现把各种文件转换成pdf文件
- 无证程序员被拘留后——linux能正常运行的程序,php系统调用时却不能运行!!!!!
- 创业团队寻PHP中高级开发人员,(可以兼职,>4K/月)(湖南地区最好, 其他地区也不限)
- 怎么这么少人用haep类型的表啊?资料找到不多。要注意些什么?
- 如何得到从别的网站来的IP?也就是类似网站统计,能统计从哪个IP网站来的。
- smartemplate缓存疑问:为何无法生成缓存文件?
- 谁能给我一个确实能用的防刷新的计算器,是文本类型的。
- iframe的高度随内容自动增大问题?
- 各位哥哥,急求解决关于Apache的问题
- php 会员退出后,如何防止页面后退?
- Wepress发布v1.0.1.0
或者你自己写个分页符啊
$i = 0;
$k = 1;
$j = 0;
$wn = 0;
$s = '';
$e = 1;
$yh = 0;
while ($k) {
$d = $content[$i];
if ($d !== '') {
if (ord($d) > 127) {
$j++;
$num = 2;
$i++;
} else {
$num = 1;
}
$j++;
} else {
if ($s) {
$listdb[] = addslashes($s);
}
$k = 0;
}
$v1 = $j - $num;
$w = substr($content, $v1, $num);
if ($w !== '') {
if ($w == '<') {
$e = 0;
}
if (!$e && $w == '"') {
$yh++;
}
if ($e && $w != ' ' && $w != ' ') {
$wn++;
}
if ($w == '>' && $yh % 2 == 0) {
$e = 1;
}
$s .= $w;
}
if ($wn >= $length && $e) {
$listdb[] = addslashes($s);
$s = '';
$wn = 0;
}
$i++;
}
return $listdb;
}
$page_per = 3000; //每页字数
//wap网页里显示文章时只需保留<img><br/>两种标识即可,其它的老给过滤掉
$content = str_replace(array('<p>','</p>','<br />'),'<br/>',$content); //替换掉段落标记
//$content = strip_tags($article, "<img>,<br/>"); //清除不需要的HTML标记
$article_list = explode_content($content, $page_per); //拆分文章
$page_count = count($article_list);
$page = !empty($_GET['page']) ? intval($_GET['page']) : 1;
$page = ($page > $page_count && $page_count>0) ? $page_count : $page;
$article = stripslashes($article_list[$page -1]);
echo $article;
if ($page_count>1) {
if ($page == 1) {
$page_code = "<a href=\"info.php?id=$id&page=".($page+1)."\">下页</a> <a href=\"info.php?id=$id&page=$page_count\">末页</a> ";
}
elseif ($page == $page_count) {
$page_code = "<a href=\"info.php?id=$id&page=".($page-1)."\">上页</a> <a href=\"info.php?id=$id&page=1\">首页</a> ";
} else {
$page_code = "<a href=\"info.php?id=$id&page=".($page+1)."\">下页</a> <a href=\"info.php?id=$id&page=".($page-1)."\">上页</a> ";
}
}这是一为高人在网上发布的帖子,还得到了他的指点,非常感谢他
这段代码的网址是:http://jihome.cn/post/239
贴出来和大家分享
//一段很长的代码后,新闻的内容读出来了。//把内容进切割。
$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;
}
貼上来,希望对楼主有用。