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


PHP domDocument::getElementsByTagNameNS方法代碼示例

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


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

示例1: get_items_datas

 protected function get_items_datas($link)
 {
     if ($link) {
         $datas = array();
         @ini_set("zend.ze1_compatibility_mode", "0");
         $informations = array();
         $loaded = false;
         $aCurl = new Curl();
         $aCurl->timeout = 2;
         $content = $aCurl->get($link);
         $flux = $content->body;
         if ($flux && $content->headers['Status-Code'] == 200) {
             $rss = new domDocument();
             $old_errors_value = false;
             if (libxml_use_internal_errors(true)) {
                 $old_errors_value = true;
             }
             $loaded = $rss->loadXML($flux);
             if (!count(libxml_get_errors())) {
                 if ($loaded) {
                     //les infos sur le flux...
                     //Flux RSS
                     $sxe = new SimpleXMLElement($flux);
                     $ns = $sxe->getNamespaces(true);
                     $informations['items'] = array();
                     if ($rss->getElementsByTagName("channel")->length > 0) {
                         $channel = $rss->getElementsByTagName("channel")->item(0);
                         $elements = array('url');
                         $informations = $this->get_informations($channel, $elements, 1);
                         //on va lire les infos des items...
                         $rss_items = $rss->getElementsByTagName("item");
                         $elements = array('title', 'description', 'link', 'pubDate', 'category', 'content');
                         $count = 0;
                         for ($i = 0; $i < $rss_items->length; $i++) {
                             if ($this->parameters['nb_max_elements'] == 0 || $i < $this->parameters['nb_max_elements']) {
                                 $informations['items'][$count] = $this->get_informations($rss_items->item($i), $elements, false);
                                 if ($ns["dc"]) {
                                     $namespace_dc_date = $rss->getElementsByTagNameNS($ns["dc"], 'date')->item($i)->nodeValue;
                                     if ($namespace_dc_date) {
                                         $informations['items'][$count]['pubDate'] = str_replace(array("T", "Z"), " ", $namespace_dc_date);
                                     }
                                     $namespace_dc_subject = $rss->getElementsByTagNameNS($ns["dc"], 'subject')->item($i)->nodeValue;
                                     if ($namespace_dc_subject) {
                                         $informations['items'][$count]['subject'] = $namespace_dc_subject;
                                     }
                                 }
                                 $count++;
                             }
                         }
                         //Flux ATOM
                     } elseif ($rss->getElementsByTagName("feed")->length > 0) {
                         $feed = $rss->getElementsByTagName("feed")->item(0);
                         $atom_elements = array('url');
                         $informations = $this->get_atom_informations($feed, $atom_elements, 1);
                         //on va lire les infos des entries...
                         $informations['items'] = array();
                         $entries = $rss->getElementsByTagName("entry");
                         $atom_elements = array('title', 'link', 'published', 'content');
                         for ($i = 0; $i < $entries->length; $i++) {
                             if ($this->parameters['nb_max_elements'] == 0 || $i < $this->parameters['nb_max_elements']) {
                                 $informations['items'][] = $this->get_atom_informations($entries->item($i), $atom_elements, false);
                             }
                         }
                     }
                     foreach ($informations['items'] as $rss_item) {
                         $data = array();
                         $data["type"] = "rss";
                         $data["title"] = $rss_item["title"];
                         $data["summary"] = $rss_item["description"];
                         $data["content"] = $rss_item["content"];
                         $data["url"] = $rss_item["link"];
                         if ($rss_item["pubDate"]) {
                             $data["publication_date"] = date('Y-m-d h:i:s', strtotime($rss_item["pubDate"]));
                         } else {
                             $data["publication_date"] = "";
                         }
                         $data["logo_url"] = $informations["url"];
                         $data["descriptors"] = "";
                         if (is_array($rss_item["category"])) {
                             $data["tags"] = array_map("strip_tags", $rss_item["category"]);
                         } else {
                             $data["tags"] = strip_tags($rss_item["category"]);
                         }
                         $datas[] = $data;
                     }
                 }
             } else {
                 libxml_clear_errors();
             }
         }
         libxml_use_internal_errors($old_errors_value);
         @ini_set("zend.ze1_compatibility_mode", "1");
         return $datas;
     } else {
         return false;
     }
 }
開發者ID:noble82,項目名稱:proyectos-ULS,代碼行數:97,代碼來源:docwatch_datasource_rss.class.php

示例2: viewInfo

    echo $node->nodeValue . "<br/>";
}
echo "--------------------------------------<br/>";
function viewInfo($node)
{
    $parent = $node->parentNode->nodeName;
    $name = $node->nodeName;
    $value = $node->nodeValue;
    echo "Родитель: {$parent}<br/>";
    echo "Имя: {$name}<br/>";
    echo "Значение: {$value}<br/>";
    echo "Дети: ";
    for ($child = $node->firstChild; $child; $child = $child->nextSibling) {
        echo $child->nodeName . " = " . $child->nodeValue . ", ";
    }
    echo "<br/> Атрибуты: ";
    $namednodmap = $node->attributes;
    for ($i = 0; $i < $namednodmap->length; $i++) {
        $attr = $namednodmap->item($i);
        echo $attr->nodeName . " = " . $attr->nodeValue;
    }
}
viewInfo($root);
echo "<br/>--------------------------------------<br/>";
$nodelist = $document->getElementsByTagNameNS("http://php.loc", "el");
for ($i = 0; $i < $nodelist->length; $i++) {
    $node = $nodelist->item($i);
    echo $node->nodeName . "<br/>";
    echo $node->nodeValue . "<br/>";
}
echo $root->getAttributeNodeNS("http://php.loc", "attr")->nodeName;
開發者ID:echmaster,項目名稱:data,代碼行數:31,代碼來源:15+Выборка+узлов+из+XML-документа+в+PHP.php


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