本文整理匯總了PHP中phpQuery::DOMNodeListToArray方法的典型用法代碼示例。如果您正苦於以下問題:PHP phpQuery::DOMNodeListToArray方法的具體用法?PHP phpQuery::DOMNodeListToArray怎麽用?PHP phpQuery::DOMNodeListToArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類phpQuery
的用法示例。
在下文中一共展示了phpQuery::DOMNodeListToArray方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: markup
/**
* Return document markup, starting with optional $nodes as root.
*
* @param $nodes DOMNode|DOMNodeList
* @return string
*/
public function markup($nodes = null, $innerMarkup = false)
{
if (isset($nodes) && count($nodes) == 1 && $nodes[0] instanceof DOMDOCUMENT) {
$nodes = null;
}
if (isset($nodes)) {
$markup = '';
if (!is_array($nodes) && !$nodes instanceof DOMNODELIST) {
$nodes = array($nodes);
}
if ($this->isDocumentFragment && !$innerMarkup) {
foreach ($nodes as $i => $node) {
if ($node->isSameNode($this->root)) {
// var_dump($node);
$nodes = array_slice($nodes, 0, $i) + phpQuery::DOMNodeListToArray($node->childNodes) + array_slice($nodes, $i + 1);
}
}
}
if ($this->isXML && !$innerMarkup) {
self::debug("Getting outerXML with charset '{$this->charset}'");
// we need outerXML, so we can benefit from
// $node param support in saveXML()
foreach ($nodes as $node) {
$markup .= $this->document->saveXML($node);
}
} else {
$loop = array();
if ($innerMarkup) {
foreach ($nodes as $node) {
if ($node->childNodes) {
foreach ($node->childNodes as $child) {
$loop[] = $child;
}
} else {
$loop[] = $node;
}
}
} else {
$loop = $nodes;
}
self::debug("Getting markup, moving selected nodes (" . count($loop) . ") to new DocumentFragment");
$fake = $this->documentFragmentCreate($loop);
$markup = $this->documentFragmentToMarkup($fake);
}
if ($this->isXHTML) {
self::debug("Fixing XHTML");
$markup = self::markupFixXHTML($markup);
}
self::debug("Markup: " . substr($markup, 0, 250));
return $markup;
} else {
if ($this->isDocumentFragment) {
// documentFragment, html only...
self::debug("Getting markup, DocumentFragment detected");
// return $this->markup(
//// $this->document->getElementsByTagName('body')->item(0)
// $this->document->root, true
// );
$markup = $this->documentFragmentToMarkup($this);
// no need for markupFixXHTML, as it's done thought markup($nodes) method
return $markup;
} else {
self::debug("Getting markup (" . ($this->isXML ? 'XML' : 'HTML') . "), final with charset '{$this->charset}'");
$markup = $this->isXML ? $this->document->saveXML() : $this->document->saveHTML();
if ($this->isXHTML) {
self::debug("Fixing XHTML");
$markup = self::markupFixXHTML($markup);
}
self::debug("Markup: " . substr($markup, 0, 250));
return $markup;
}
}
}