-2

我有一个带有大文本的数据库字段。如果里面有标签,<!-- new page -->我想按该标签分页。

当您插入诸如<!-- new page -->我想创建新页面之类的标签时,我正在尝试做的事情就像 WordPress 一样。

假设我有来自数据库的文本

Lorem ipsum dolor sit amet, consectetur adipiscing elit。Quisque elementum magna in nulla ultrices,eu pulvinar nulla auctor。Praesent auctor ut dui vitae feugiat。

<!-- new page -->

sed risus nisl, tristique sed tristique et, auctor eu augue。在 hac habitasse platea dictumst 中。融合 ipsum ligula。Aliquam 前庭 ligula ut ligula porta gravida。Curabitur tincidunt a est vitae eleifend。Duis ullamcorper nunc sapien, quis molestie tellus ornare vel。努拉姆在米埃罗斯。

如何让第二段出现在新页面上?

像这样http://en.support.wordpress.com/splitting-content/nextpage/

4

1 回答 1

2

我希望我的代码会有所帮助:

<?php
//in this example :
//first you have to create a database with name : blog
// create table : article (id as primary key, name , content)
// here we supposed that in the content you have your tags <!-- new page -->
// also i supposed the name of this file as : pagination.php

//Getting the id of article:
//=========================
if(isset($_GET['id']))
    $id_article = $_GET['id'];
else
    $id_article = 1;



//Connexion to database :
//======================
$user="root";
$pass="root";
$db="blog";
$host="localhost";

$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host='.$host.';dbname='.$db, $user, $pass, $pdo_options);
$bdd->query("SET NAMES 'utf8'");


$response = $bdd->query('SELECT * FROM articles WHERE id='.$id_article);

$tab_content = array();

$data = $response->fetch()
echo'<div >';
    $tab_content = explode('<!-- new page -->',$data['content']);
    $count_pages = count($tab_content);
    if($count_pages){
            //in the case that you have somme tags :
            //=====================================
        echo $tab_content[$page];
        echo '<br>';
        for($i=1;$i<$count_pages;$i++)
            echo '<a href="./pagination.php?id='.$id_article.'&page='.$i.'">'.$i.'</a>&nbsp;&nbsp;';
    }
    else{
            //if no tags '<!-- new page -->' in your content:
            //===============================================
        echo $data['content'];
    }
echo '</div>';

$response->closeCursor();

?>
于 2013-11-08T09:38:21.580 回答