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


PHP DOMDocument::getElementsByTagName方法代码示例

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


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

示例1: createArray

 /**
  *
  * Convert the $source string into a array.
  * This array should always respect the scheme defined by the
  * getDataFromSource method of the ServiceDriver
  * @param string $source
  * @return string
  */
 public function createArray($source, $driver, $url, &$errorFlag)
 {
     // trying to load XML into DOM Document
     $doc = new DOMDocument();
     $doc->preserveWhiteSpace = false;
     $doc->formatOutput = false;
     // ignore errors, but save it if was successful
     $errorFlag = !@$doc->loadXML($source);
     if (!$errorFlag) {
         $xml['xml'] = @$doc->saveXML();
         if ($xml['xml'] === FALSE) {
             $errorFlag = true;
         } else {
             // add id to array
             $idTagName = $driver->getIdTagName();
             if ($idTagName == null) {
                 $xml['id'] = Lang::createHandle($url);
             } else {
                 $xml['id'] = $doc->getElementsByTagName($idTagName)->item(0)->nodeValue;
             }
             $xml['title'] = $doc->getElementsByTagName($driver->getTitleTagName())->item(0)->nodeValue;
             $xml['thumb'] = $doc->getElementsByTagName($driver->getThumbnailTagName())->item(0)->nodeValue;
         }
     }
     if ($errorFlag) {
         // return error message
         $xml['error'] = __('Symphony could not parse XML from oEmbed remote service');
     }
     return $xml;
 }
开发者ID:justinjaywang,项目名称:oembed_field,代码行数:38,代码来源:class.parser.xml.php

示例2: loadRulesFromDom

 public function loadRulesFromDom()
 {
     $styles = $this->dom->getElementsByTagName('style');
     foreach ($styles as $style_node) {
         $this->rules = array_merge($this->rules, self::parse($style_node->nodeValue));
     }
 }
开发者ID:xprt64,项目名称:php-css,代码行数:7,代码来源:Parser.php

示例3: listParties

 public static function listParties()
 {
     $doc = new DOMDocument();
     $doc->load(self::parties);
     $codes = $doc->getElementsByTagName("Codigo");
     $names = $doc->getElementsByTagName("Nombre");
     //return value structure
     $listParties = array();
     $codeArray = array();
     $nameArray = array();
     //main information array
     foreach ($codes as $node) {
         array_push($codeArray, $node->nodeValue);
     }
     foreach ($names as $node) {
         array_push($nameArray, $node->nodeValue);
     }
     for ($i = 0; $i < count($codeArray); $i++) {
         $code = $codeArray[$i];
         $name = $nameArray[$i];
         $account = new Account($code, $name);
         array_push($listParties, $account);
     }
     return $listParties;
 }
开发者ID:santirogu,项目名称:generarComprobantes,代码行数:25,代码来源:XMLManager.php

示例4: getPlayerRssfeed

 public function getPlayerRssfeed($playername)
 {
     $returnArray = [];
     $xml = "https://news.google.de/news/feeds?pz=1&cf=all&ned=LANGUAGE&hl=aus&q=" . $playername . "&output=rss";
     $xmlDoc = new \DOMDocument();
     $xmlDoc->load($xml);
     // get elements from "<channel>"
     $channel = $xmlDoc->getElementsByTagName('channel')->item(0);
     $returnArray['feed_title'] = $channel->getElementsByTagName('title')->item(0)->childNodes->item(0)->nodeValue;
     $returnArray['feed_link'] = $channel->getElementsByTagName('link')->item(0)->childNodes->item(0)->nodeValue;
     $returnArray['feed_desc'] = $channel->getElementsByTagName('description')->item(0)->childNodes->item(0)->nodeValue;
     $items = $xmlDoc->getElementsByTagName('channel')->item(0)->getElementsByTagName('item');
     foreach ($items as $key => $item) {
         $title = $item->getElementsByTagName('title')->item(0)->firstChild->nodeValue;
         $description = $item->getElementsByTagName('description')->item(0)->firstChild->nodeValue;
         $pubDate = $item->getElementsByTagName('pubDate')->item(0)->firstChild->nodeValue;
         $guid = $item->getElementsByTagName('guid')->item(0)->firstChild->nodeValue;
         $returnArray['item'][$key]['title'] = $title;
         $returnArray['item'][$key]['pubdate'] = $pubDate;
         /*
          * $returnArray['item'][$key]['description'] = $description;
          * $returnArray['item'][$key]['pubdate'] = $pubDate;
          * $returnArray['item'][$key]['guid'] = $guid;
          */
     }
     return $returnArray;
 }
开发者ID:pssubashps,项目名称:football,代码行数:27,代码来源:Rssfeed.php

示例5: changeApplicationXmlVersions

function changeApplicationXmlVersions($file, $versionNum, $subver)
{
    $verStr = $versionNum . "_" . $subver;
    $newFiles = getNewFileName();
    $doc = new DOMDocument();
    $doc->load($file);
    $assests = $doc->getElementsByTagName("asset");
    $modules = $doc->getElementsByTagName("module");
    foreach ($newFiles as $nfi) {
        foreach ($assests as $ai) {
            $src = $ai->getAttribute("src");
            if (strpos($src, $nfi) !== false) {
                //echo "ok<br />";
                $ai->setAttribute("version", $verStr);
            }
            $src = $ai->nodeValue;
            if (strpos($src, $nfi) !== false) {
                $ai->setAttribute("version", $verStr);
                //echo "ok<br />";
            }
        }
        foreach ($modules as $mi) {
            $src = $mi->getAttribute("src");
            if (strpos($src, $nfi) !== false) {
                $mi->setAttribute("version", $verStr);
                //echo "ok  $nfi<br />";
            }
        }
    }
    $doc->save($file);
}
开发者ID:sewonist,项目名称:yangsj,代码行数:31,代码来源:changefiles.php

示例6: getMeta

 function getMeta($url)
 {
     $cache = $this->cache->getPageMeta($url);
     if (!empty($cache)) {
         return $cache;
     }
     $html = $this->file_get_contents_curl($url);
     $doc = new \DOMDocument();
     @$doc->loadHTML($html);
     $nodes = $doc->getElementsByTagName('title');
     $title = $nodes->item(0)->nodeValue;
     $metas = $doc->getElementsByTagName('meta');
     $values = array('title' => $title);
     for ($i = 0; $i < $metas->length; $i++) {
         $meta = $metas->item($i);
         $id = $meta->getAttribute('name');
         if (empty($id)) {
             $id = $meta->getAttribute('property');
         }
         if (!empty($id)) {
             $values[$id] = $meta->getAttribute('content');
         }
     }
     $this->cache->storePageMeta($url, $values);
     return $values;
 }
开发者ID:ridewing,项目名称:wp-superpowers,代码行数:26,代码来源:Request.php

示例7: update

 function update()
 {
     // Cree un objet pour accueillir le contenu du RSS : un document XML
     $doc = new DOMDocument();
     //Telecharge le fichier XML dans $rss
     $doc->load($this->url);
     // Recupère la liste (DOMNodeList) de tous les elements de l'arbre 'title'
     $nodeList = $doc->getElementsByTagName('title');
     // Met à jour le titre dans l'objet
     $this->titre = $nodeList->item(0)->textContent;
     // Recupère la liste de toutes les dates
     $nodeList = $doc->getElementsByTagName('pubDate');
     //Met à jour la date dans l'objet
     $this->date = $nodeList->item(0)->textContent;
     //recupère la liste des url
     $nodeList = $doc->getElementsByTagName('link');
     //met à jour la date dans l'objet
     $this->url = $nodeList->item(0)->textContent;
     //met à jour l'image de l'objet
     $nodeList = $doc->getElementsByTagName('enclosure');
     $this->enclosure = $nodeList->item(0)->textContent;
     $nomLocalImage = 1;
     // Recupère tous les items du flux RSS
     foreach ($doc->getElementsByTagName('item') as $node) {
         $nouvelle = new Nouvelle();
         // Met à jour la nouvelle avec l'information téléchargée
         $nouvelle->update($node);
         // Télécharge l'image
         $nouvelle->downloadImage($node, $nomLocalImage);
         // on ajoute la nouvelle courante a la liste
         $this->nouvelles[] = $nouvelle;
     }
 }
开发者ID:sHynig4mi,项目名称:YouRSS,代码行数:33,代码来源:RSS.class.php

示例8: parse

 public function parse($html)
 {
     if (empty($html)) {
         $this->title = $this->message = 'Empty exception';
         $this->sourceFile = '';
         return false;
     }
     if (!$this->domDocument) {
         $this->domDocument = new \DOMDocument();
     }
     @$this->domDocument->loadHTML($html);
     $titleItem = $this->domDocument->getElementsByTagName("title")->item(0);
     $this->title = $titleItem ? $titleItem->textContent : 'N/A';
     try {
         $sourceFileElement = $this->domDocument->getElementById("tracy-bs-error");
         if (is_object($sourceFileElement)) {
             $sourceFileLinkNode = $sourceFileElement->getElementsByTagName("a")->item(0);
             $this->sourceFile = trim($sourceFileLinkNode->textContent);
         } else {
             $this->sourceFile = 'Unknown format of exception';
         }
         $messageNode = $this->domDocument->getElementsByTagName("p")->item(0);
         if (is_object($messageNode)) {
             $messageNode->removeChild($messageNode->lastChild);
             $this->message = trim($messageNode->textContent);
         } else {
             $this->message = 'Unable to parse';
         }
     } catch (\Exception $e) {
         $this->message = 'Unable to parse';
     }
 }
开发者ID:RiKap,项目名称:ErrorMonitoring,代码行数:32,代码来源:ExceptionParser.php

示例9: getVideoData

 public static function getVideoData($videoid, $customimage, $customtitle, $customdescription)
 {
     $theTitle = '';
     $Description = '';
     $theImage = '';
     $videodata = array();
     if (phpversion() < 5) {
         return "Update to PHP 5+";
     }
     try {
         $url = 'http://api.own3d.tv/rest/video/list.xml?videoid=' . $videoid;
         $htmlcode = YouTubeGalleryMisc::getURLData($url);
         if (strpos($htmlcode, '<?xml version') === false) {
             $pair = array('Invalid id', 'Invalid id', '', '0', '0', '0', '0', '0', '0', '0', '');
             return $pair;
         }
         $doc = new DOMDocument();
         $doc->loadXML($htmlcode);
         $video_thumb_file_small = 'http://owned.vo.llnwd.net/v1/static/static/images/thumbnails/tn_' . $videoid . '__1.jpg';
         $videodata = array('videosource' => 'own3dtvvideo', 'videoid' => $videoid, 'imageurl' => $video_thumb_file_small, 'title' => $doc->getElementsByTagName("video_name")->item(0)->nodeValue, 'description' => $doc->getElementsByTagName("video_description")->item(0)->nodeValue, 'publisheddate' => "", 'duration' => $doc->getElementsByTagName("video_duration")->item(0)->nodeValue, 'rating_average' => 0, 'rating_max' => 0, 'rating_min' => 0, 'rating_numRaters' => 0, 'statistics_favoriteCount' => 0, 'statistics_viewCount' => $doc->getElementsByTagName("video_views_total")->item(0)->nodeValue, 'keywords' => '');
         return $videodata;
     } catch (Exception $e) {
         return 'cannot get youtube video data';
     }
     return array('videosource' => 'own3dtvvideo', 'videoid' => $videoid, 'imageurl' => $theImage, 'title' => $theTitle, 'description' => $Description);
 }
开发者ID:VierlingMt,项目名称:joomla-3.x,代码行数:26,代码来源:own3dtvvideo.php

示例10: process

 public function process($xml)
 {
     $this->step = 0;
     $xml = $this->preprocessXml($xml);
     $xml = $this->handleSimpleSnippets($xml);
     // Add a snippet to trigger a process
     $snippetCount = count($this->parseSnippetsInString($xml));
     if ($snippetCount == 0) {
         $xml .= "<filler>[str_replace('a','b','c')]</filler>";
     }
     // While we have snippets
     while ($snippetCount = count($this->parseSnippetsInString($xml))) {
         $this->step++;
         $xml = '<root>' . $xml . '</root>';
         $this->initVariables($xml);
         $root = $this->dom->getElementsByTagName("root");
         $this->dom->recover = true;
         $this->parseElement($root->item(0));
         $this->dom->preserveWhiteSpace = false;
         $this->dom->formatOutput = true;
         $response = $this->dom->saveXML($this->dom);
         $xml = $this->cleanResponse($xml, $response);
         if ($this->step > 8) {
             throw new WpaeTooMuchRecursionException('Too much recursion');
         }
     }
     $xml = $this->postProcessXml($xml);
     $xml = $this->decodeSpecialCharacters($xml);
     $xml = $this->encodeSpecialCharsInAttributes($xml);
     return $xml;
 }
开发者ID:soflyy,项目名称:wp-all-export,代码行数:31,代码来源:WpaeXmlProcessor.php

示例11: modify

 function modify($tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters)
 {
     switch ($operatorName) {
         case 'parsexml':
             $firstParam = $namedParameters['first_param'];
             if (trim($operatorValue) != '') {
                 $dom = new DOMDocument('1.0', 'utf-8');
                 if ($dom->loadXML($operatorValue)) {
                     $FileAttributeValue = $dom->getElementsByTagName($firstParam)->item(0)->textContent;
                     if (!$FileAttributeValue) {
                         $FileAttributeValue = $dom->getElementsByTagName($firstParam)->item(0)->getAttribute('value');
                     }
                 }
                 $operatorValue = $FileAttributeValue;
             }
             break;
         case 'filecheck':
             if (trim($operatorValue) != '') {
                 $dom = new DOMDocument('1.0', 'utf-8');
                 if ($dom->loadXML($operatorValue)) {
                     $FileAttributeValue = $dom->getElementsByTagName('Filename')->item(0)->textContent;
                     if (!$FileAttributeValue) {
                         $FileAttributeValue = $dom->getElementsByTagName('Filename')->item(0)->getAttribute('value');
                     }
                 }
                 if (file_exists(eZSys::wwwDir() . $FileAttributeValue)) {
                     $operatorValue = true;
                 } else {
                     $operatorValue = false;
                 }
             }
             break;
     }
 }
开发者ID:Alexnder,项目名称:enhancedezbinaryfile,代码行数:34,代码来源:templateparsexmloperator.php

示例12: actionNotifyalipay

 public function actionNotifyalipay()
 {
     $user_id = Yii::app()->user->id;
     $alipay = Yii::app()->alipay;
     $verify_result = $alipay->verifyNotify();
     if ($verify_result) {
         $doc = new DOMDocument();
         $doc->loadXML($notify_data);
         if (!empty($doc->getElementsByTagName("notify")->item(0)->nodeValue)) {
             //商户订单号
             $out_trade_no = $doc->getElementsByTagName("out_trade_no")->item(0)->nodeValue;
             //支付宝交易号
             $trade_no = $doc->getElementsByTagName("trade_no")->item(0)->nodeValue;
             //交易状态
             $trade_status = $doc->getElementsByTagName("trade_status")->item(0)->nodeValue;
             //接口示例文件中,下面用的$_POST['trade_status'],但是我用POST获取不到值,直接用上面取出的$trade_status也可以。
             if ($trade_status == 'TRADE_FINISHED' || $trade_status == 'TRADE_SUCCESS') {
                 //判断该订单是否已处理
                 //处理业务逻辑
                 echo 'success';
             }
         }
     } else {
         echo 'fail';
     }
 }
开发者ID:linuxwit,项目名称:mf,代码行数:26,代码来源:PayController.php

示例13: XmlAuthResponse

 public function XmlAuthResponse($responseXml)
 {
     $doc = new DOMDocument();
     $doc->loadXML($responseXml);
     try {
         if (strpos($responseXml, "ERROR")) {
             $responseNodes = $doc->getElementsByTagName("ERROR");
             foreach ($responseNodes as $node) {
                 $this->errorString = $node->getElementsByTagName('ERRORSTRING')->item(0)->nodeValue;
             }
             $this->isError = true;
         } else {
             if (strpos($responseXml, "PAYMENTRESPONSE")) {
                 $responseNodes = $doc->getElementsByTagName("PAYMENTRESPONSE");
                 foreach ($responseNodes as $node) {
                     $this->uniqueRef = $node->getElementsByTagName('UNIQUEREF')->item(0)->nodeValue;
                     $this->responseCode = $node->getElementsByTagName('RESPONSECODE')->item(0)->nodeValue;
                     $this->responseText = $node->getElementsByTagName('RESPONSETEXT')->item(0)->nodeValue;
                     $this->approvalCode = $node->getElementsByTagName('APPROVALCODE')->item(0)->nodeValue;
                     $this->authorizedAmount = $node->getElementsByTagName('AUTHORIZEDAMOUNT')->item(0)->nodeValue;
                     $this->dateTime = $node->getElementsByTagName('DATETIME')->item(0)->nodeValue;
                     $this->avsResponse = $node->getElementsByTagName('AVSRESPONSE')->item(0)->nodeValue;
                     $this->cvvResponse = $node->getElementsByTagName('CVVRESPONSE')->item(0)->nodeValue;
                     $this->hash = $node->getElementsByTagName('HASH')->item(0)->nodeValue;
                 }
             } else {
                 throw new Exception("Invalid Response");
             }
         }
     } catch (Exception $e) {
         $this->isError = true;
         $this->errorString = $e->getMessage();
     }
 }
开发者ID:sanchojaf,项目名称:oldmytriptocuba,代码行数:34,代码来源:xmlresponse.php

示例14: testCreate

 public function testCreate()
 {
     $crawler = $this->client->request('GET', $this->getUrl('orocrm_sales_lead_create'));
     /** @var Form $form */
     $form = $crawler->selectButton('Save and Close')->form();
     $name = 'name' . $this->generateRandomString();
     $form['orocrm_sales_lead_form[name]'] = $name;
     $form['orocrm_sales_lead_form[firstName]'] = 'firstName';
     $form['orocrm_sales_lead_form[lastName]'] = 'lastName';
     $form['orocrm_sales_lead_form[address][city]'] = 'City Name';
     $form['orocrm_sales_lead_form[address][label]'] = 'Main Address';
     $form['orocrm_sales_lead_form[address][postalCode]'] = '10000';
     $form['orocrm_sales_lead_form[address][street2]'] = 'Second Street';
     $form['orocrm_sales_lead_form[address][street]'] = 'Main Street';
     $form['orocrm_sales_lead_form[companyName]'] = 'Company';
     $form['orocrm_sales_lead_form[email]'] = 'test@example.test';
     $form['orocrm_sales_lead_form[owner]'] = 1;
     $form['orocrm_sales_lead_form[dataChannel]'] = $this->getReference('default_channel')->getId();
     $doc = new \DOMDocument("1.0");
     $doc->loadHTML('<select name="orocrm_sales_lead_form[address][country]" id="orocrm_sales_lead_form_address_country" ' . 'tabindex="-1" class="select2-offscreen"> ' . '<option value="" selected="selected"></option> ' . '<option value="US">United States</option> </select>');
     $field = new ChoiceFormField($doc->getElementsByTagName('select')->item(0));
     $form->set($field);
     $doc->loadHTML('<select name="orocrm_sales_lead_form[address][region]" id="orocrm_sales_lead_form_address_region" ' . 'tabindex="-1" class="select2-offscreen"> ' . '<option value="" selected="selected"></option> ' . '<option value="US-CA">California</option> </select>');
     $field = new ChoiceFormField($doc->getElementsByTagName('select')->item(0));
     $form->set($field);
     $form['orocrm_sales_lead_form[address][country]'] = 'US';
     $form['orocrm_sales_lead_form[address][region]'] = 'US-CA';
     $this->client->followRedirects(true);
     $crawler = $this->client->submit($form);
     $result = $this->client->getResponse();
     $this->assertHtmlResponseStatusCodeEquals($result, 200);
     $this->assertContains("Lead saved", $crawler->html());
     return $name;
 }
开发者ID:antrampa,项目名称:crm,代码行数:34,代码来源:LeadControllersTest.php

示例15: rsky_modify_link_posts

function rsky_modify_link_posts($data)
{
    //Get content
    $dom = new DOMDocument();
    $dom->loadHTML($data);
    foreach ($dom->getElementsByTagName('a') as $node) {
        if ($node->hasAttribute('href')) {
            if (!$node->hasAttribute('title')) {
                $url = $node->getAttribute('href')->textContent;
                $url = esc_url_raw(trim($url, '"'));
                $args = array('sslverify' => false);
                $webpage = wp_remote_get($url);
                if (!is_wp_error($webpage)) {
                    if (wp_remote_retrieve_response_code($webpage) === 200 && ($body = wp_remote_retrieve_body($webpage))) {
                        $remote_dom = new DOMDocument();
                        $remote_dom->loadHTML($body);
                        $title = $dom->getElementsByTagName('title');
                        if ($title->length > 0) {
                            $node->setAttribute('title', $title->item(0)->textContent);
                        }
                    }
                }
            }
        }
    }
    $data = preg_replace('/^<!DOCTYPE.+?>/', '', str_replace(array('<html>', '</html>', '<body>', '</body>'), array('', '', '', ''), $dom->saveHTML()));
    return $data;
}
开发者ID:robertsky,项目名称:wp-modifylinks,代码行数:28,代码来源:wp-modifylinks.php


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