【发布时间】:2012-05-15 07:55:54
【问题描述】:
该类通过在它找到的任何地方展开内容来工作 [next]。但问题是 next 被包裹在 div 中,所以它变成了<div>[next]</div>,这是因为我使用的是所见即所得的编辑器。当它在第一页上找到 [next] 时,</div> 在它被带到第二页之后等等,阻碍了布局。
所以展示文本的类:
function splitText($pageCont){
$this->textarray = explode('[next]', $pageCont);
$this->numPages = count($this->textarray);
}
以及回显文本块的类
function getContent(){
if($this->page != 0){
echo $this->pageCont;
} else {
echo $this->textarray[0];
}
}
问题是,我怎样才能阻止这种情况发生,或者使主 div 中的 div 不会影响页面布局?好像现在当 div 吐出时,它会将右列推到右下角
由 kuh-chan 编辑的完整代码
class Pagebreak {
private $page; //page number
private $numPages; //number of total pages
private $textarray = array(); // array of conents
private $pageCont; //current page content
public function __construct(){
if (!isset($_GET['page'])) {
$this->page = 0;
} else {
$this->page = $_GET['page'];
}
}
public function splitText($pageCont){
$this->textarray = preg_split('/(?<!\<div\>)\[next\]/', $pageCont);
$this->numPages = count($this->textarray);
}
public function setPage(){
$this->pageCont = $this->textarray[$_GET['page'] -1];
}
public function getContent(){
if($this->page != 0){
echo $this->pageCont;
} else {
echo $this->textarray[0];
}
}
public function getPageLinks(){
echo "<p class=\"article_page_div\">\n";
//prev page
//if page number is more then 1 show previous link
if ($this->page > 1) {
$prevpage = $this->page - 1;
echo "<a class=\"article_paging\" href=\"?post=".$_GET['post']."&page=$prevpage\">". 'Prev</a> ';
}
//page numbers
for($i = 1; $i <= $this->numPages ; $i++){
if($this->numPages > 1){ // if more then 1 page show links
if(($this->page) == $i){ //if page number is equal page number in loop don't link it
echo "$i\n ";
} else {
if($this->page == 0){ //if no page numbers have been clicked don't link first page link
if($i == 1){
echo "$i\n ";
} else { // link the rest
echo "<a class=\"article_paging\" href=\"?post=".$_GET['post']."&page=$i\">$i</a>\n ";
}
} else { // link pages
echo "<a class=\"article_paging\" href=\"?post=".$_GET['post']."&page=$i\">$i</a>\n ";
}
}
}
}
//next page
//if page number is less then the total number of pages show next link
if ($this->page <= $this->numPages - 1) {
if($this->page == 0){ //if no page numbers have been clicked minus 2 from the next page link
$nextpage = $this->page + 2;
} else {
$nextpage = $this->page + 1;
}
echo "<a class=\"article_paging\" href=\"?post=".$_GET['post']."&page=$nextpage\">". 'Next</a>';
}
echo "</p>\n";
}
}
然后调用这个你只需使用的类:
$paginate = new Pagebreak();
$paginate->splitText($storyCont);
$paginate->setPage();
$paginate->getContent();
$paginate->getPageLinks();
【问题讨论】:
-
尝试 preg_split 负前瞻
-
啊哈!!越来越近了....不过,您将如何编写该函数的表达式?
$this->textarray = preg_split("function", $pageCont);因为 '[next]' 不起作用 -
我实际上有 split() 而不是 explode 一开始但我得到了函数 split() is deprecated 这就是为什么我改为explode。
-
类似 preg_split("/(?)[next]/",$pageCont)
-
我刚刚尝试了这个表达式,它写了大约 600 页,即使我将 [next] 完全从文章中取出...我假设它为每个 div 创建一个新页面,不确定
标签: css class pagination html