当前位置: 首页>>代码示例>>PHP>>正文


PHP DOMNodeList::getDocumentID方法代码示例

本文整理汇总了PHP中DOMNodeList::getDocumentID方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMNodeList::getDocumentID方法的具体用法?PHP DOMNodeList::getDocumentID怎么用?PHP DOMNodeList::getDocumentID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DOMNodeList的用法示例。


在下文中一共展示了DOMNodeList::getDocumentID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: pq

 /**
  * Multi-purpose function.
  * Use pq() as shortcut.
  *
  * In below examples, $pq is any result of pq(); function.
  *
  * 1. Import markup into existing document (without any attaching):
  * - Import into selected document:
  *   pq('<div/>')				// DOESNT accept text nodes at beginning of input string !
  * - Import into document with ID from $pq->getDocumentID():
  *   pq('<div/>', $pq->getDocumentID())
  * - Import into same document as DOMNode belongs to:
  *   pq('<div/>', DOMNode)
  * - Import into document from phpQuery object:
  *   pq('<div/>', $pq)
  *
  * 2. Run query:
  * - Run query on last selected document:
  *   pq('div.myClass')
  * - Run query on document with ID from $pq->getDocumentID():
  *   pq('div.myClass', $pq->getDocumentID())
  * - Run query on same document as DOMNode belongs to and use node(s)as root for query:
  *   pq('div.myClass', DOMNode)
  * - Run query on document from phpQuery object
  *   and use object's stack as root node(s) for query:
  *   pq('div.myClass', $pq)
  *
  * @param string|DOMNode|DOMNodeList|array	$arg1	HTML markup, CSS Selector, DOMNode or array of DOMNodes
  * @param string|phpQueryObject|DOMNode	$context	DOM ID from $pq->getDocumentID(), phpQuery object (determines also query root) or DOMNode (determines also query root)
  *
  * @return phpQueryObject|QueryTemplatesSource|QueryTemplatesParse|QueryTemplatesSourceQuery|QueryTemplatesPhpQuery|false
  * phpQuery object or false in case of error.
  */
 public static function pq($arg1, $context = null)
 {
     if ($arg1 instanceof DOMNODE && !isset($context)) {
         foreach (phpQuery::$documents as $documentWrapper) {
             $compare = $arg1 instanceof DOMDocument ? $arg1 : $arg1->ownerDocument;
             if ($documentWrapper->document->isSameNode($compare)) {
                 $context = $documentWrapper->id;
             }
         }
     }
     if (!$context) {
         $domId = self::$defaultDocumentID;
         if (!$domId) {
             throw new Exception("Can't use last created DOM, because there isn't any. Use phpQuery::newDocument() first.");
         }
         //		} else if (is_object($context) && ($context instanceof PHPQUERY || is_subclass_of($context, 'phpQueryObject')))
     } else {
         if (is_object($context) && $context instanceof phpQueryObject) {
             $domId = $context->getDocumentID();
         } else {
             if ($context instanceof DOMDOCUMENT) {
                 $domId = self::getDocumentID($context);
                 if (!$domId) {
                     //throw new Exception('Orphaned DOMDocument');
                     $domId = self::newDocument($context)->getDocumentID();
                 }
             } else {
                 if ($context instanceof DOMNODE) {
                     $domId = self::getDocumentID($context);
                     if (!$domId) {
                         throw new Exception('Orphaned DOMNode');
                         //				$domId = self::newDocument($context->ownerDocument);
                     }
                 } else {
                     $domId = $context;
                 }
             }
         }
     }
     if ($arg1 instanceof phpQueryObject) {
         //		if (is_object($arg1) && (get_class($arg1) == 'phpQueryObject' || $arg1 instanceof PHPQUERY || is_subclass_of($arg1, 'phpQueryObject'))) {
         /**
          * Return $arg1 or import $arg1 stack if document differs:
          * pq(pq('<div/>'))
          */
         if ($arg1->getDocumentID() == $domId) {
             return $arg1;
         }
         $class = get_class($arg1);
         // support inheritance by passing old object to overloaded constructor
         $phpQuery = $class != 'phpQuery' ? new $class($arg1, $domId) : new phpQueryObject($domId);
         $phpQuery->elements = array();
         foreach ($arg1->elements as $node) {
             $phpQuery->elements[] = $phpQuery->document->importNode($node, true);
         }
         return $phpQuery;
     } else {
         if ($arg1 instanceof DOMNODE || is_array($arg1) && isset($arg1[0]) && $arg1[0] instanceof DOMNODE) {
             /*
              * Wrap DOM nodes with phpQuery object, import into document when needed:
              * pq(array($domNode1, $domNode2))
              */
             $phpQuery = new phpQueryObject($domId);
             if (!$arg1 instanceof DOMNODELIST && !is_array($arg1)) {
                 $arg1 = array($arg1);
             }
             $phpQuery->elements = array();
//.........这里部分代码省略.........
开发者ID:RetroscopeCreative,项目名称:RouterunnerCMS,代码行数:101,代码来源:phpQuery.php


注:本文中的DOMNodeList::getDocumentID方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。