本文整理汇总了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;
}
}