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


PHP DomDocument::normalize方法代碼示例

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


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

示例1: run

 public function run($str = NULL)
 {
     if ($str == NULL) {
         return $this;
     }
     $document = jqm_use($this->node->_parentElement);
     $dom = $document->_DOM;
     if ($dom->doctype) {
         $dom->removeChild($dom->doctype);
     }
     $find = $this->node->getPathById($dom);
     if (!$find) {
         $find = $this->node->_path;
     }
     $xpath = new DomXpath($dom);
     $find = $xpath->query($find);
     if ($find->length > 0) {
         $child = new DomDocument();
         $child->loadHtml($str);
         if ($child->doctype) {
             $child->removeChild($child->doctype);
         }
         $child->normalize();
         $frag = $dom->importNode($child->firstChild->firstChild->firstChild, true);
         $save = $find->item(0)->parentNode->insertBefore($frag, $find->item(0));
         $this->node->_path = $save->nextSibling->getNodePath();
         $document->_DOM = $dom;
     }
     return $this;
 }
開發者ID:Webictbyleo,項目名稱:JqueryPhp,代碼行數:30,代碼來源:before.php

示例2: getPreview

 public function getPreview($elements)
 {
     if (!isset($this->preview)) {
         if (!isset($elements)) {
             $elements = 2;
         }
         // Get just the text (no markup) from a node using $node->textContent.
         // Compare the textContent value to the one returned by $node->nodeValue.
         libxml_use_internal_errors(true);
         $dom = new DomDocument();
         $dom->preserveWhiteSpace = false;
         $dom->loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $this->Body . '</body></html>');
         $dom->normalize();
         $nodes = $dom->getElementsByTagName("body")->item(0)->childNodes;
         $elementCount = 0;
         $this->preview = '';
         foreach ($nodes as $node) {
             if ($node->nodeType === XML_ELEMENT_NODE) {
                 $this->preview .= $dom->saveXML($node);
                 $elementCount++;
                 if ($elementCount === $elements) {
                     break;
                 }
             }
         }
         // Carriage returns in the XML prevent the markup from validating. -- cwells
         $this->preview = str_replace('&#13;', '', $this->preview);
     }
     return $this->preview;
 }
開發者ID:chriswells0,項目名稱:cwa-blog,代碼行數:30,代碼來源:BlogPost.php


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