我有一个包含大文本的数据库字段。如果<!-- new page -->
里面有一个标签,我想按该标签分页。
我正在尝试做的是像WordPress一样,当您插入诸如<!-- new page -->
我想创建一个新页面之类的标签时。
假设我有来自数据库的文本
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 习惯高原格言中。大惊小怪。Aliquam vestibulum ligula ut ligula porta gravida.Curabitur tincidunt a est vitae eleifend.Duis ullamcorper nunc sapien, quis molestie tellus ornare vel.Nullam in mi eros.
如何使第二段显示在新页面上?
像这样的东西 http://en.support.wordpress.com/splitting-content/nextpage/
我希望我的代码会有所帮助:
<?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> ';
}
else{
//if no tags '<!-- new page -->' in your content:
//===============================================
echo $data['content'];
}
echo '</div>';
$response->closeCursor();
?>