php處理ckeditor分頁符有關問題

來源:互聯網
上載者:User
php處理ckeditor分頁符問題

ckeditor有個分頁的按鈕,能夠插入分頁符,但這隻是在編輯時顯示的效果而已,要真正實現分頁,還需要其它語言,這裡使用php採取一種方法來實現分頁,當然還有其它的方法可以實現。

這裡使用的方法是:在顯示的頁面讀取資料後,根據ckeditor插入的分頁代碼將內容分成幾部分存放在資料中,ckeditor源碼中插入的分頁代碼是:

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

在Firefox中插入的代碼也是如此,但是如果是在ie中編輯,則插入的代碼是:

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

因此,在將內容轉為數組時,使用Regex進行匹配以防止不同瀏覽器儲存的內容不一致。匹配的Regex如下:

“/\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;

}

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.