sports98 于 2006-9-8 16:22:12 加贴在 PHP ←返回版面:

如果文章系统内输入的 文章长度太长,需要进行分页。下面的代码思想则比较有用。建议封装起来后使用,可以扩展以分割符号(段落符配合使用 ,请注意中文切词)
<?php
$content = "hello world asdfaslkd asdf asd f asd fa sdf asd f asd fas df asd fa sdf da s f asd fas df asd f asdf as df";
$content .= "hello world asdfaslkd asdf asd f asd fa sdf asd f asd fas df asd fa sdf da s f asd fas df asd f asdf as df";
$Page_size = 20;
$Current_page = isset($_GET['n'])?intval($_GET['n']):1;
$Total_page = ceil(strlen($content) / $Page_size);
$Start_size = ($Current_page -1)*$Page_size;
$Page_outinfo = "第";
for($i=1;$i<=$Total_page;$i++)
{
$Page_outinfo .= "<a href=\"$_SERVER[PHP_SELF]?n=$i\">$i</a> ";
}
$Page_outinfo .= "页";
$Page_outinfo = Substr($content,$Start_size,$Page_size)."<br/><p align=\"right\">".$Page_outinfo."</p>";
echo $Page_outinfo;
?>
计算机世界开发者俱乐部 http://dev-club.esnai.com
你觉得本精华贴如何? 请给本精华贴打分

|
|
* 游客不能打分。
|
|
|

-
[原创]文章分页 -- 备查 - sports98 2006-9-8 16:22:12 [ID:2575471 点击:1064] (873 Bytes) (2)
-
回复:[原创]文章分页 -- 备查 - neatstudio 2008-5-17 10:57:32 [ID:2580396 点击:203] (102 Bytes) (0)
-
顶一下,冒个泡 <无内容> - hq22 2006-9-10 19:32:17 [ID:2575490 点击:1619] (0 Bytes) (0)