文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>长文章分页

长文章分页

时间:2008-07-02  来源:liuxingyuyuni

看了
http://hi.baidu.com/drckness/blog/item/d6682b542e732b1a3b2935ef.html

就试着写了一下代码如下(仅供参考):


?php
    $content = '蝇是枯吃老本gfdgdfg村枯无可厚非afgfd地古4442一二眄上战无不胜蝶恋花435放产fd辨辨首席首席';
    /**
     * Long article split
     * @author BianYuan
     * @param     String $content
     * @param    Integer $perPageChar
     * @param    String    $charset
     * @param    Array $conf
     * @return     Array part of article info and links tag
     **/
    function getPartOfContent($content, $perPageChar, $charset='UTF-8', $conf=array())
    {
        if(!isset($conf['p']) || !isset($conf['linkSpacing']))
         die('Cant not get article part index');
        
        $content = strip_tags((string)$content);
        $perPageChar = (int)$perPageChar;
        $charset = (string)$charset;
        
        $totalChar = mb_strlen($content, $charset);
        $numPage = ceil($totalChar/$perPageChar);
        $pageLinks = '';
        for($pageIndex=1; $pageIndex=$numPage; $pageIndex++)
        {
            $offset = ($pageIndex-1)*$perPageChar;
            $splitContent[$pageIndex] = mb_substr($content, $offset, $perPageChar, $charset);
            if($conf['p'] != $pageIndex) {
                $pageLinks .= ".$conf['linkStyle'].
                 "' href='".$_SERVER['PHP_SELF']."?p=".
                 $pageIndex."'>{$pageIndex}".$conf['linkSpacing'];
            }
            else
            {
                $pageLinks .= $pageIndex . $conf['linkSpacing'];
            }   
        }
        return array(
            $splitContent[$conf['p']],
            $pageLinks
        );
    }
   
    $p = isset($_GET['p']) ? $p=$_GET['p']:1;
    $conf = array(
        'p' => intval($p),
        'linkSpacing' => ' | ',
        'linkStyle' => 'default'
    );
    $info = getPartOfContent($content, 10,'UTF-8', $conf);
?>
!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
html>
head>
meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
title>Example/title>
/head>
body>
div id="body">
    div id="articleBody">
        ?php echo $info[0]; ?>
    /div>
    br />
    div id="links">
        ?php echo $info[1]; ?>
    /div>
/div>
/body>
/html>


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载