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


PHP DOMDocument::getElementsBytagName方法代码示例

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


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

示例1: getProductInfo

    public function getProductInfo($l)
    {
        /*
         Image Url's:
        	      list view:http://img6a.flixcart.com/image/computer/m/h/8/lenovo-ideapad-notebook-125x125-imadd4f7jrzuchmg.jpeg
        	      thumbnail:http://img6a.flixcart.com/image/computer/m/h/8/lenovo-ideapad-notebook-400x400-imadd4f7jrzuchmg.jpeg
        	small thumbnail:http://img6a.flixcart.com/image/computer/m/h/8/lenovo-ideapad-notebook-100x100-imadd4f7jrzuchmg.jpeg
        	 Available dimensions: 
        	  100X100
        	  125X125
        	  200X200
        	  400X400
        */
        echo "<h5>Link:" . $l->link . "</h5>";
        $ch = curl_init($l->link);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        $content = curl_exec($ch);
        if ($content === false) {
            echo "Waittt:::" . $content;
            echo 'Curl error: ' . curl_error($ch);
            flush();
            return false;
        }
        $dom = new DOMDocument();
        @$dom->loadHTML($content);
        $data = array();
        $data['product_code'] = $l->product_code;
        $title = $dom->getElementById("specifications");
        if (is_object($title)) {
            foreach ($title->childNodes as $c1) {
                if (isset($c1->tagName) && $c1->tagName == "h3" && $c1->getAttribute("class") == "item_desc_title fk-uppercase") {
                    $data['title'] = $c1->nodeValue;
                    if (substr_count($data['title'], "Specifications of") > 0) {
                        $data['title'] = str_replace("Specifications of", "", $data['title']);
                    }
                    break;
                }
            }
        } else {
            $title = $dom->getElementsByTagName("title");
            foreach ($title as $c1) {
                if (isset($c1->tagName) && $c1->tagName == "title") {
                    $data['title'] = $c1->nodeValue;
                    break;
                }
            }
        }
        $data['title'] = trim($data['title']);
        $price = $dom->getElementsBytagName("meta");
        foreach ($price as $p) {
            if (isset($p->tagName) && $p->tagName == "meta" && $p->getAttribute("itemprop") == "price") {
                $data['price'] = trim($p->getAttribute("content"));
                break;
            }
        }
        foreach ($price as $p) {
            if (isset($p->tagName) && $p->tagName == "meta" && $p->getAttribute("itemprop") == "ratingValue") {
                $data['star_rate'] = trim($p->getAttribute("content"));
                break;
            }
        }
        $data['link'] = $l->link;
        $data['parent_link'] = $l->parent_link;
        $specifications = $dom->getElementsBytagName("td");
        $c = 0;
        foreach ($specifications as $s) {
            //specs-key
            //specs-value fk-data
            if ($s->nodeValue == null) {
                continue;
            }
            if ($s->getAttribute("class") == "specs-key") {
                $key = $s->nodeValue;
                if (isset($data['brand']) && strtolower($s->nodeValue) == "brand") {
                    $key = "processor_brand";
                }
                // echo $s->nodeValue;
                $c++;
            } else {
                if ($s->getAttribute("class") == "specs-value fk-data") {
                    $value = $s->nodeValue;
                    //echo ":".$s->nodeValue;
                    $c++;
                }
            }
            if ($c == 2) {
                $data[strtolower(str_replace(' ', '_', trim($key)))] = trim($value);
                $c = 0;
                //echo "<hr/>";
            }
        }
        $description = $dom->getElementsByTagName("ul");
        if ($description) {
            foreach ($description as $d) {
                $class = $d->getAttribute("class");
                if (isset($d->tagName) && $d->tagName == "ul" && ($class == "fk-key-features" || $class == "feature_bullet")) {
                    $data['description'] = trim($this->getInnerHTML($d));
                    break;
                }
//.........这里部分代码省略.........
开发者ID:anmolview,项目名称:yiidemos,代码行数:101,代码来源:SunderlandEcho.php

示例2: replaceWithIcons

 /**
  * Replace labels shown in list view with icons (if found)
  *
  * @param   string  $data  Data
  * @param   string  $view  List/details
  * @param   string  $tmpl  Template
  *
  * @since 3.0 - icon_folder is a bool - search through template folders for icons
  *
  * @return  string	data
  */
 protected function replaceWithIcons($data, $view = 'list', $tmpl = null)
 {
     if ($data == '') {
         $this->iconsSet = false;
         return $data;
     }
     $params = $this->getParams();
     $listModel = $this->getListModel();
     $iconFile = (string) $params->get('icon_file', '');
     if ((int) $params->get('icon_folder', 0) === 0 && $iconFile === '') {
         $this->iconsSet = false;
         return $data;
     }
     if (in_array($listModel->getOutPutFormat(), array('csv', 'rss'))) {
         $this->iconsSet = false;
         return $data;
     }
     $cleanData = empty($iconFile) ? FabrikString::clean(strip_tags($data)) : $iconFile;
     $cleanDatas = array($this->getElement()->name . '_' . $cleanData, $cleanData);
     $opts = array('forceImage' => true);
     //If subdir is set prepend file name with subdirectory (so first search through [template folders]/subdir for icons, e.g. images/subdir)
     $iconSubDir = $params->get('icon_subdir', '');
     if ($iconSubDir != '') {
         $iconSubDir = rtrim($iconSubDir, '/') . '/';
         $iconSubDir = ltrim($iconSubDir, '/');
         array_unshift($cleanDatas, $iconSubDir . $cleanData);
         //search subdir first
     }
     foreach ($cleanDatas as $cleanData) {
         foreach ($this->imageExtensions as $ex) {
             $img = FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), false, $opts);
             if ($img !== '') {
                 $this->iconsSet = true;
                 $opts = new stdClass();
                 $opts->position = 'top';
                 $opts = json_encode($opts);
                 $data = '<span>' . $data . '</span>';
                 // See if data has an <a> tag
                 if (class_exists('DOMDocument')) {
                     $html = new DOMDocument();
                     /**
                      * The loadXML() chokes if data has & in it.  But we can't htmlspecialchar() it, as that removes
                      * the HTML markup we're looking for.  So we need to ONLY change &'s which aren't already part of
                      * any HTML entities which may be in the data.  So use a negative lookahead regex, which finds & followed
                      * by anything except non-space the ;.  Then after doing the loadXML, we have to turn the &amp;s back in
                      * to &, to avoid double encoding 'cos we're going to do an htmpsepecialchars() on $data in a few lines.
                      */
                     $data = preg_replace('/&(?!\\S+;)/', '&amp;', $data);
                     $html->loadXML($data);
                     $data = str_replace('&amp;', '&', $data);
                     $as = $html->getElementsBytagName('a');
                 }
                 if ($params->get('icon_hovertext', true)) {
                     $aHref = '#';
                     $target = '';
                     if (class_exists('DOMDocument') && $as->length) {
                         // Data already has an <a href="foo"> lets get that for use in hover text
                         $a = $as->item(0);
                         $aHref = $a->getAttribute('href');
                         $target = $a->getAttribute('target');
                         $target = 'target="' . $target . '"';
                     }
                     $data = htmlspecialchars($data, ENT_QUOTES);
                     $img = '<a class="fabrikTip" ' . $target . ' href="' . $aHref . '" opts=\'' . $opts . '\' title="' . $data . '">' . $img . '</a>';
                 } elseif (!empty($iconFile)) {
                     /**
                      * $$$ hugh - kind of a hack, but ... if this is an upload element, it may already be a link, and
                      * we'll need to replace the text in the link with the image
                      * After ages dicking around with a regex to do this, decided to use DOMDocument instead!
                      */
                     if (class_exists('DOMDocument') && $as->length) {
                         $img = $html->createElement('img');
                         $src = FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), true, array('forceImage' => true));
                         $img->setAttribute('src', $src);
                         $as->item(0)->nodeValue = '';
                         $as->item(0)->appendChild($img);
                         return $html->saveHTML();
                     }
                 }
                 return $img;
             }
         }
     }
     return $data;
 }
开发者ID:LGBGit,项目名称:tierno,代码行数:96,代码来源:element.php

示例3: _replaceWithIcons

 /**
  * Replace labels shown in table view with icons (if found)
  *
  * @param   string  $data  data
  * @param   string  $view  list/details
  * @param   string  $tmpl  template
  *
  * @since 3.0 - icon_folder is a bool - search through template folders for icons
  *
  * @return  string	data
  */
 protected function _replaceWithIcons($data, $view = 'list', $tmpl = null)
 {
     if ($data == '') {
         $this->iconsSet = false;
         return $data;
     }
     $params = $this->getParams();
     if ((int) $params->get('icon_folder', 0) === 0) {
         $this->iconsSet = false;
         return $data;
     }
     $listModel = $this->getListModel();
     if (in_array($listModel->getOutPutFormat(), array('csv', 'rss'))) {
         $this->iconsSet = false;
         return $data;
     }
     /**
      * Jaanus added this and following if/else; sometimes we need permanent image
      * (e.g logo of the website where the link always points, like Wikipedia's W)
      */
     $iconfile = $params->get('icon_file', '');
     $cleanData = $iconfile === '' ? FabrikString::clean(strip_tags($data)) : $iconfile;
     foreach ($this->_imageExtensions as $ex) {
         $f = JPath::clean($cleanData . '.' . $ex);
         $img = FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl);
         if ($img !== '') {
             $this->iconsSet = true;
             $opts = new stdClass();
             $opts->position = 'top';
             $opts = json_encode($opts);
             $data = '<span>' . $data . '</span>';
             if ($params->get('icon_hovertext', true)) {
                 $data = htmlspecialchars($data, ENT_QUOTES);
                 $img = '<a class="fabrikTip" href="#" opts=\'' . $opts . '\' title="' . $data . '">' . $img . '</a>';
             } elseif (!empty($iconfile)) {
                 /**
                  * $$$ hugh - kind of a hack, but ... if this is an upload element, it may already be a link, and
                  * we'll need to replace the text in the link with the image
                  * After ages dicking around with a regex to do this, decided to use DOMDocument instead!
                  */
                 $html = new DOMDocument();
                 $html->loadXML($data);
                 $as = $html->getElementsBytagName('a');
                 if ($as->length) {
                     $img = $html->createElement('img');
                     $img->setAttribute('src', FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), true));
                     $as->item(0)->nodeValue = '';
                     $as->item(0)->appendChild($img);
                     return $html->saveHTML();
                 }
             }
             return $img;
         }
     }
     $this->iconsSet = false;
     return $data;
 }
开发者ID:rogeriocc,项目名称:fabrik,代码行数:68,代码来源:element.php

示例4: replaceWithIcons

 /**
  * Replace labels shown in list view with icons (if found)
  *
  * @param   string  $data  Data
  * @param   string  $view  List/details
  * @param   string  $tmpl  Template
  *
  * @since 3.0 - icon_folder is a bool - search through template folders for icons
  *
  * @return  string	data
  */
 protected function replaceWithIcons($data, $view = 'list', $tmpl = null)
 {
     if ($data == '') {
         $this->iconsSet = false;
         return $data;
     }
     $params = $this->getParams();
     $listModel = $this->getListModel();
     $iconFile = (string) $params->get('icon_file', '');
     if ((int) $params->get('icon_folder', 0) === 0 && $iconFile === '') {
         $this->iconsSet = false;
         return $data;
     }
     if (in_array($listModel->getOutPutFormat(), array('csv', 'rss'))) {
         $this->iconsSet = false;
         return $data;
     }
     $cleanData = empty($iconFile) ? FabrikString::clean(strip_tags($data)) : $iconFile;
     $cleanDatas = array($this->getElement()->name . '_' . $cleanData, $cleanData);
     $opts = array('forceImage' => true);
     foreach ($cleanDatas as $cleanData) {
         foreach ($this->imageExtensions as $ex) {
             $f = JPath::clean($cleanData . '.' . $ex);
             $img = FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), false, $opts);
             if ($img !== '') {
                 $this->iconsSet = true;
                 $opts = new stdClass();
                 $opts->position = 'top';
                 $opts = json_encode($opts);
                 $data = '<span>' . $data . '</span>';
                 // See if data has an <a> tag
                 if (class_exists('DOMDocument')) {
                     $html = new DOMDocument();
                     $html->loadXML($data);
                     $as = $html->getElementsBytagName('a');
                 }
                 if ($params->get('icon_hovertext', true)) {
                     $ahref = '#';
                     $target = '';
                     if (class_exists('DOMDocument') && $as->length) {
                         // Data already has an <a href="foo"> lets get that for use in hover text
                         $a = $as->item(0);
                         $ahref = $a->getAttribute('href');
                         $target = $a->getAttribute('target');
                         $target = 'target="' . $target . '"';
                     }
                     $data = htmlspecialchars($data, ENT_QUOTES);
                     $img = '<a class="fabrikTip" ' . $target . ' href="' . $ahref . '" opts=\'' . $opts . '\' title="' . $data . '">' . $img . '</a>';
                 } elseif (!empty($iconFile)) {
                     /**
                      * $$$ hugh - kind of a hack, but ... if this is an upload element, it may already be a link, and
                      * we'll need to replace the text in the link with the image
                      * After ages dicking around with a regex to do this, decided to use DOMDocument instead!
                      */
                     if (class_exists('DOMDocument') && $as->length) {
                         $img = $html->createElement('img');
                         $img->setAttribute('src', FabrikHelperHTML::image($cleanData . '.' . $ex, $view, $tmpl, array(), true));
                         $as->item(0)->nodeValue = '';
                         $as->item(0)->appendChild($img);
                         return $html->saveHTML();
                     }
                 }
                 return $img;
             }
         }
     }
     return $data;
 }
开发者ID:ppantilla,项目名称:bbninja,代码行数:79,代码来源:element.php


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