当前位置: 首页>>代码示例>>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;未经允许,请勿转载。