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


PHP Zend_Feed_Abstract::getDomDocument方法代碼示例

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


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

示例1: detectType

 /**
  * Detect the feed type of the provided feed
  *
  * @param  Zend_Feed_Abstract|DOMDocument|string $feed
  * @return string
  */
 public static function detectType($feed, $specOnly = false)
 {
     if ($feed instanceof Zend_Feed_Reader_FeedInterface) {
         $dom = $feed->getDomDocument();
     } elseif ($feed instanceof DOMDocument) {
         $dom = $feed;
     } elseif (is_string($feed) && !empty($feed)) {
         @ini_set('track_errors', 1);
         $dom = new DOMDocument();
         $status = @$dom->loadXML($feed);
         @ini_restore('track_errors');
         if (!$status) {
             if (!isset($php_errormsg)) {
                 if (function_exists('xdebug_is_enabled')) {
                     $php_errormsg = '(error message not available, when XDebug is running)';
                 } else {
                     $php_errormsg = '(error message not available)';
                 }
             }
             require_once 'Zend/Feed/Exception.php';
             throw new Zend_Feed_Exception("DOMDocument cannot parse XML: {$php_errormsg}");
         }
     } else {
         require_once 'Zend/Feed/Exception.php';
         throw new Zend_Feed_Exception('Invalid object/scalar provided: must' . ' be of type Zend_Feed_Reader_FeedInterface, DomDocument or string');
     }
     $xpath = new DOMXPath($dom);
     if ($xpath->query('/rss')->length) {
         $type = self::TYPE_RSS_ANY;
         $version = $xpath->evaluate('string(/rss/@version)');
         if (strlen($version) > 0) {
             switch ($version) {
                 case '2.0':
                     $type = self::TYPE_RSS_20;
                     break;
                 case '0.94':
                     $type = self::TYPE_RSS_094;
                     break;
                 case '0.93':
                     $type = self::TYPE_RSS_093;
                     break;
                 case '0.92':
                     $type = self::TYPE_RSS_092;
                     break;
                 case '0.91':
                     $type = self::TYPE_RSS_091;
                     break;
             }
         }
         return $type;
     }
     $xpath->registerNamespace('rdf', self::NAMESPACE_RDF);
     if ($xpath->query('/rdf:RDF')->length) {
         $xpath->registerNamespace('rss', self::NAMESPACE_RSS_10);
         if ($xpath->query('/rdf:RDF/rss:channel')->length || $xpath->query('/rdf:RDF/rss:image')->length || $xpath->query('/rdf:RDF/rss:item')->length || $xpath->query('/rdf:RDF/rss:textinput')->length) {
             return self::TYPE_RSS_10;
         }
         $xpath->registerNamespace('rss', self::NAMESPACE_RSS_090);
         if ($xpath->query('/rdf:RDF/rss:channel')->length || $xpath->query('/rdf:RDF/rss:image')->length || $xpath->query('/rdf:RDF/rss:item')->length || $xpath->query('/rdf:RDF/rss:textinput')->length) {
             return self::TYPE_RSS_090;
         }
     }
     $type = self::TYPE_ATOM_ANY;
     $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_10);
     if ($xpath->query('//atom:feed')->length) {
         return self::TYPE_ATOM_10;
     }
     if ($xpath->query('//atom:entry')->length) {
         if ($specOnly == true) {
             return self::TYPE_ATOM_10;
         } else {
             return self::TYPE_ATOM_10_ENTRY;
         }
     }
     $xpath->registerNamespace('atom', self::NAMESPACE_ATOM_03);
     if ($xpath->query('//atom:feed')->length) {
         return self::TYPE_ATOM_03;
     }
     return self::TYPE_ANY;
 }
開發者ID:anunay,項目名稱:stentors,代碼行數:86,代碼來源:Reader.php


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