當前位置: 首頁>>代碼示例>>PHP>>正文


PHP HTMLPage::addNode方法代碼示例

本文整理匯總了PHP中HTMLPage::addNode方法的典型用法代碼示例。如果您正苦於以下問題:PHP HTMLPage::addNode方法的具體用法?PHP HTMLPage::addNode怎麽用?PHP HTMLPage::addNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在HTMLPage的用法示例。


在下文中一共展示了HTMLPage::addNode方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: __construct

 public function __construct($html, $encoding, $pageNumber, $paragraphsPerPage = HTMLPager::PARAGRAPH_LIMIT)
 {
     $dom = new DOMDocument();
     libxml_use_internal_errors(true);
     libxml_clear_errors();
     // clean up any errors belonging to other operations
     $dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', $encoding));
     foreach (libxml_get_errors() as $error) {
         Kurogo::log(LOG_WARNING, "HTMLPager got loadHTML warning (line {$error->line}; column {$error->column}) {$error->message}", 'data');
     }
     libxml_clear_errors();
     // free up memory associated with the errors
     libxml_use_internal_errors(false);
     $body = $dom->getElementsByTagName("body")->item(0);
     $currentPage = NULL;
     $pages = array();
     $currentParagraphCount = 0;
     foreach ($body->childNodes as $node) {
         if ($currentPage == NULL) {
             // need to start a new page
             if ($node->nodeName == "#text" && trim($node->nodeValue) == "") {
                 continue;
                 // this node is blank so do not start a new page yet
             }
             $currentPage = new HTMLPage();
             $pages[] = $currentPage;
         }
         $currentPage->addNode($node);
         if ($node->nodeName == "p") {
             $currentParagraphCount++;
         }
         if ($currentParagraphCount == $paragraphsPerPage) {
             $currentPage = NULL;
             $currentParagraphCount = 0;
         }
     }
     $this->pages = $pages;
     $this->pageCount = count($pages);
     if ($pageNumber >= 0 && $pageNumber < $this->pageCount) {
         $this->pageNumber = $pageNumber;
     }
 }
開發者ID:nncsang,項目名稱:Kurogo,代碼行數:42,代碼來源:HTMLPager.php


注:本文中的HTMLPage::addNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。