本文整理汇总了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;
}
示例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(' ', '', $this->preview);
}
return $this->preview;
}