PHP头条
热点:

php处理ckeditor分页符有关问题


php处理ckeditor分页符问题

ckeditor有个分页的按钮,能够插入分页符,但这只是在编辑时显示的效果而已,要真正实现分页,还需要其它语言,这里使用php采取一种方法来实现分页,当然还有其它的方法可以实现。

这里使用的方法是:在显示的页面读取数据后,根据ckeditor插入的分页代码将内容分成几部分存放在数据中,ckeditor源码中插入的分页代码是:

 style=”page-break-after: always;”> style=”display: none;”> 

在火狐中插入的代码也是如此,但是如果是在ie中编辑,则插入的代码是:

 style=”page-break-after: always”> style=”display: none”> 

因此,在将内容转为数组时,使用正则表达式进行匹配以防止不同浏览器保存的内容不一致。匹配的正则表达式如下:

“/\s* <\/span>\s*<\/div>/”

我在测试时,与之间被添加换行符,所以用了“\s*”进行匹配,在后边的与之间也用了“ \s*”进行匹配以防万一。将此功能写成函数,如下:

/**  * 获取文章内容(当前分页)

*   * @param string $content 文章内容

* @param integer $page 页数

* @return array

*/  

function get_article_content($content, $page=1){

$page = $page ? intval($page) :

$article = array(   ’info’ => array(),  ’pages’ => 1       );

if(!emptyempty($content)){

$pattern = ”/\s* <\/span>\s*<\/div>/”;            $contents = preg_split($pattern, $content);

$article['pages'] = count($contents);

($page > $article['pages']) && $page = $article['pages'];

$article['info'] = $contents[$page - 1];

}

return $article;

}

www.phpzy.comtrue/phprm/55351.htmlTechArticlephp处理ckeditor分页符有关问题 php处理ckeditor分页符问题 ckeditor有个分页的按钮,能够插入分页符,但这只是在编辑时显示的效果而已,要真正实现分页,还需要其它语言,这里使用php采...

相关文章

PHP之友评论

今天推荐