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


PHP DOMXpath::query方法代码示例

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


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

示例1: apply

 /**
  * {@inheritdoc}
  */
 public function apply(base $databox, Application $app)
 {
     $structure = $databox->get_structure();
     $DOM = new DOMDocument();
     $DOM->loadXML($structure);
     $xpath = new DOMXpath($DOM);
     foreach ($xpath->query('/record/subdefs/subdefgroup[@name="video"]/subdef[@name="preview"]/acodec') as $node) {
         $node->nodeValue = 'libvo_aacenc';
     }
     foreach ($xpath->query('/record/subdefs/subdefgroup[@name="video"]/subdef[@name="preview"]/vcodec') as $node) {
         $node->nodeValue = 'libx264';
     }
     $databox->saveStructure($DOM);
     $subdefgroups = $databox->get_subdef_structure();
     foreach ($subdefgroups as $groupname => $subdefs) {
         foreach ($subdefs as $name => $subdef) {
             $this->addScreenDeviceOption($subdefgroups, $subdef, $groupname);
             if (in_array($name, ['preview', 'thumbnail'])) {
                 if ($name == 'thumbnail' || $subdef->getSubdefType()->getType() != \Alchemy\Phrasea\Media\Subdef\Subdef::TYPE_VIDEO) {
                     $this->addMobileSubdefImage($subdefgroups, $subdef, $groupname);
                 } else {
                     $this->addMobileSubdefVideo($subdefgroups, $subdef, $groupname);
                 }
             }
             if ($subdef->getSubdefType()->getType() != \Alchemy\Phrasea\Media\Subdef\Subdef::TYPE_VIDEO) {
                 continue;
             }
             $this->addHtml5Video($subdefgroups, $subdef, $groupname);
         }
     }
     return true;
 }
开发者ID:nlegoff,项目名称:Phraseanet,代码行数:35,代码来源:370alpha6a.php

示例2: LINKS

 public static function LINKS($url)
 {
     $content = file_get_contents($url);
     $doc = new \DOMDocument();
     $doc->loadHTML($content);
     // \bloc\application::instance()->log($doc);
     $xpath = new \DOMXpath($doc);
     $handle = curl_init("https://validator.nu/?level=error&doc={$url}&out=json");
     curl_setopt_array($handle, [CURLOPT_RETURNTRANSFER => true, CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT']]);
     $report = json_decode(curl_exec($handle));
     $number_of_errors = count($report->messages);
     $files = [['name' => 'index.html', 'content' => $content, 'type' => 'lang-html', 'url' => $url, 'report' => ['count' => count($report->messages), 'errors' => (new \bloc\types\Dictionary($report->messages))->map(function ($item) {
         return ['line' => $item->lastLine ?? 1, 'message' => $item->message];
     })]], ['name' => 'README', 'content' => null, 'type' => 'plain-text', 'url' => base64_encode($url . '/readme.txt')]];
     foreach ($xpath->query("//script[@src and not(contains(@src, 'http'))]") as $file) {
         $src = $file->getAttribute('src');
         $files[] = ['url' => base64_encode($url . '/' . $src), 'name' => substr($src, strrpos($src, '/') + 1), 'content' => null, 'type' => 'lang-js'];
     }
     foreach ($xpath->query("//link[not(contains(@href, 'http')) and contains(@href, '.css')]") as $file) {
         $src = $file->getAttribute('href');
         $uri = $url . '/' . $src;
         $code = substr(get_headers($uri)[0], 9, 3);
         if ($code < 400) {
             $report = json_decode(file_get_contents("https://jigsaw.w3.org/css-validator/validator?output=json&warning=0&profile=css3&uri=" . $uri));
             $count = $report->cssvalidation->result->errorcount;
         } else {
             $report = 'not-found';
             $count = "fix";
         }
         $files[] = ['url' => base64_encode($uri), 'name' => substr($src, strrpos($src, '/') + 1), 'content' => null, 'type' => 'lang-css', 'report' => ['count' => $count, 'errors' => (new \bloc\types\Dictionary($report->cssvalidation->errors ?? []))->map(function ($item) {
             return ['line' => $item->line, 'message' => $item->message];
         })]];
     }
     return $files;
 }
开发者ID:brendanmetzger,项目名称:ledger,代码行数:35,代码来源:assessment.php

示例3: buildMeta

 /**
  * Retreives a list of tags for a given resource that are marked
  * "Sujet principal". 
  * 
  * With the "non_principal_fallback" option set to TRUE, in the
  * event that there are no "sujet principal" tags, all the tags will
  * be used instead.
  *
  * (There should probably be a parameter for the string "Sujet
  * principal".)
  *
  * @param $url Optional. Defaults to current page.
  * @param $non_principal_fallback boolean Get all tags if there are NO "sujet principal".
  * @returns folksoPageDataMeta object
  */
 public function buildMeta($url = NULL, $max_tags = 0, $non_principal_fallback = NULL)
 {
     $mt = new folksoPageDataMeta();
     $this->getData($url);
     /** could set a maximum here, but instead we can
                                   set that at display time, since we might be 
                                   reusing data. 
     
                                   NB: if $url is NULL, getData() will use
                                   $this->url anyway.
                               **/
     if ($this->is_valid()) {
         $xpath = new DOMXpath($this->xml_DOM());
         // reusing existing DOM, maybe
         //$tag_princ is a DOMNodelist object
         $tag_princ = $xpath->query('//taglist/tag[metatag="Sujet principal"]');
         // 'Sujet principal' only
         if ($tag_princ->length > 0) {
             foreach ($tag_princ as $element) {
                 $tagname = $element->getElementsByTagName('display');
                 $mt->add_principal_keyword($tagname->item(0)->textContent);
             }
         }
         // All tags, when no 'sujet principal' is found.
         $all_tags = $xpath->query('//taglist/tag');
         if ($all_tags->length > 0) {
             foreach ($all_tags as $element) {
                 $tagname = $element->getElementsByTagName('display');
                 $mt->add_all_tags($tagname->item(0)->textContent);
             }
         }
         $this->mt = $mt;
         return $mt;
     }
 }
开发者ID:josf,项目名称:folkso,代码行数:50,代码来源:folksoPagetags.php

示例4: loadMetaValue

 /**
  * {@inheritDoc}
  */
 protected function loadMetaValue($name, $default = NULL)
 {
     switch ($name) {
         case 'thumbnail':
             return sprintf(self::PREVIEW_IMAGE_URL, $this->lastId);
             break;
         case 'tags':
             $elements = $this->xpath->query(self::$XPATHS[$name]);
             if (!is_null($elements) && $elements->length > 0) {
                 $tags = array();
                 foreach ($elements as $element) {
                     $tags[] = $element->nodeValue;
                 }
                 return $tags;
             }
             break;
         default:
             if (!isset(self::$XPATHS[$name])) {
                 return $default;
             }
             $elements = $this->xpath->query(self::$XPATHS[$name]);
             if (!is_null($elements) && $elements->length > 0) {
                 return $elements->item(0)->nodeValue;
             }
     }
 }
开发者ID:jmcclell,项目名称:OryzoneMediaStorage,代码行数:29,代码来源:YoutubeVideoService.php

示例5: getData

 /**
  * main function extracts url data and returns json array
  * @return json array
  */
 public function getData()
 {
     $results = array();
     $total = 0;
     $htmlMain = $this->getHtml($this->url);
     $doc = new DOMDocument();
     @$doc->loadHTML($htmlMain['result']);
     $xpath = new DOMXpath($doc);
     $products = $xpath->query('//div[@class="productInfo"]');
     foreach ($products as $entry) {
         $htmlLinks = $entry->getElementsByTagName("a");
         foreach ($htmlLinks as $item) {
             $href = $item->getAttribute("href");
             $link = trim(preg_replace("/[\r\n]+/", " ", $item->nodeValue));
             $html = $this->getHtml($href);
             $doc = new DOMDocument();
             @$doc->loadHTML($html['result']);
             $xpath = new DOMXpath($doc);
             $productUnitPrice = $xpath->query('//p[@class="pricePerUnit"]');
             foreach ($productUnitPrice as $itemPrice) {
                 $unitPrice = preg_replace('/[^0-9.]*/', '', $itemPrice->nodeValue);
                 break;
             }
             $productText = $xpath->query('//div[@class="productText"]');
             foreach ($productText as $itemText) {
                 $description = trim($itemText->nodeValue);
                 break;
             }
             $results['result'][] = array('title' => $link, 'size' => $html['size'], 'unit_price' => $unitPrice, 'description' => $description);
             $total += $unitPrice;
         }
     }
     $results['total'] = $total;
     return json_encode($results);
 }
开发者ID:shilsu,项目名称:Scraper-Consoleapp,代码行数:39,代码来源:mainScraper.php

示例6: getStats

function getStats($manifestfile, $resultsfile)
{
    //At the moment just read the manifest into an array
    //$urls = file($manifestfile,FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
    //Filename will point to the text file but want to read the mfx file
    $folder = pathinfo($manifestfile, PATHINFO_DIRNAME);
    $base = pathinfo($manifestfile, PATHINFO_FILENAME);
    $mfx = "{$folder}/{$base}.mfx";
    $fp = @fopen($mfx, "r");
    //Read the first $headerlength bytes as the header
    $headerlength = 20;
    list($reclen, $totrecs) = explode(":", fread($fp, $headerlength));
    fclose($fp);
    //Open and load the required
    if ($resultsfile) {
        $doc = new DOMDocument();
        $ok = @$doc->load($resultsfile);
        if ($ok) {
            $x = new DOMXpath($doc);
            $answerlist = $x->query("/responses/response");
            $answers = $answerlist->length;
            $contributions = $x->query("/responses/response[@userid='{$userid}']");
            $yes = $x->query("/responses/response[@userid='{$userid}' and @answer='1']");
            $no = $x->query("/responses/response[@userid='{$userid}' and @answer='-1']");
            $dn = $x->query("/responses/response[@userid='{$userid}' and @answer='0']");
            echo json_encode(array(total => $totrecs, answers => $answers, contributions => $contributions->length, yes => $yes->length, no => $no->length, dontknow => $dn->length));
        } else {
            echo json_encode(array(total => $totrecs, answers => 0, contributions => 0));
        }
    } else {
        echo json_encode(array(total => $totrecs, answers => 0, contributions => 0));
    }
}
开发者ID:rbgeplantsman,项目名称:YesNo,代码行数:33,代码来源:yesnostats.php

示例7: outputScrape

function outputScrape($url)
{
    $returnvalue = "";
    $data1 = preg_replace('#(<\\/ul>\\s*)+#i', '</ul>', scrapePage($url));
    $data1a = str_replace('files//', 'http://resources21.org/cl/files/', $data1);
    $data2 = preg_replace(array('/<head>(.*)<\\/head>/iUs', '/<html>/', '/<\\/html>/', '/<body>/', '/<\\/body>/', '/<\\/td><td>/'), "", $data1a);
    $returnvalue .= '<div id="lessonplan-content">';
    $doc = new DOMDocument();
    $doc->loadHTML($data2);
    libxml_use_internal_errors(false);
    $xpath = new DOMXpath($doc);
    $elements = $xpath->query('//ul');
    $elementsh = $xpath->query("//*[@class='secHed']");
    $header = array();
    if (!is_null($elementsh)) {
        foreach ($elementsh as $elementh) {
            $header[] = "<h3>" . $elementh->nodeValue . "</h3>";
        }
    }
    if (!is_null($elements)) {
        $i = 0;
        foreach ($elements as $element) {
            $returnvalue .= '<div id="' . $element->getAttribute('id') . '">' . $header[$i] . "<ul>";
            $nodes = $element->childNodes;
            foreach ($nodes as $node) {
                $returnvalue .= '<li>' . innerXML($node) . "</li>\n";
            }
            $returnvalue .= "</ul></div>";
            $i++;
        }
        $returnvalue .= "</div>";
    }
    // $returnvalue = "<[CDATA[ " . $returnvalue ." ]]>";
    return $returnvalue;
}
开发者ID:thinkcollege,项目名称:fqi_toolkit,代码行数:35,代码来源:feed_scraper2.php

示例8: parseResults

 public function parseResults($html)
 {
     $dom = new DOMDocument();
     $dom->loadHTML($html);
     $xpath = new DOMXpath($dom);
     $elements = $xpath->query('//*[@id="nav-wrapper"]/div[2]/div/section/div/div/div[2]/div');
     $results = array();
     if (!is_null($elements)) {
         foreach ($elements as $element) {
             $str = preg_replace('/\\s+/', ' ', trim($element->nodeValue));
             preg_match('/(.*)\\s\\|\\s([a-zA-Z0-9 \\-]+).*\\s([0-9,]+).*/', $str, $matches);
             // Get product url
             $itemurl = $xpath->query('div/div/h4/a', $element);
             foreach ($itemurl as $node) {
                 $url = $node->getAttribute('href');
             }
             // Get image
             $imagenodes = $xpath->query('div/a/img', $element);
             foreach ($imagenodes as $node) {
                 $image = $node->getAttribute('src');
             }
             array_push($results, array('title' => trim($matches[1]), 'platform' => $matches[2], 'price' => $matches[3], 'url' => '//magixbuttons.com' . $url, 'img' => $image));
         }
     }
     return $results;
 }
开发者ID:mrpapercut,项目名称:gameshopsnl,代码行数:26,代码来源:MagixButtons.class.php

示例9: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     $metadata = $manager->getClassMetaData(get_class(new Operator()));
     $metadata->setIdGenerator(new \Doctrine\ORM\Id\AssignedGenerator());
     $metadata->setIdGeneratorType(\Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_NONE);
     $i = 1;
     $file = dirname(__FILE__) . '/../../operators.xml';
     $doc = new \DOMDocument();
     $doc->load($file);
     $xpath = new \DOMXpath($doc);
     $elements = $xpath->query('/operators/operator');
     if (!is_null($elements)) {
         /** @var $element DOMNode */
         foreach ($elements as $element) {
             $operator = new Operator();
             $operator->setId($i);
             $operator->setType($this->getTypeForString($element->getAttribute('type')));
             $operator->setOperator($element->getAttribute('operator'));
             $operator->setInputType($element->getAttribute('inputType'));
             // translations
             $translations = $xpath->query('translations/translation', $element);
             $this->processTranslations($manager, $operator, $translations);
             // values
             $values = $xpath->query('values/value', $element);
             $this->processValues($manager, $xpath, $operator, $values);
             $manager->persist($operator);
             ++$i;
         }
     }
     $manager->flush();
 }
开发者ID:sulu,项目名称:sulu,代码行数:34,代码来源:LoadOperators.php

示例10: parseResults

 private function parseResults($html)
 {
     $dom = new DOMDocument();
     $dom->loadHTML($html);
     $xpath = new DOMXpath($dom);
     $elements = $xpath->query('//*[@id="middenkolom"]/div/table/tbody/tr');
     $results = array();
     if (!is_null($elements)) {
         foreach ($elements as $element) {
             // Get image
             foreach ($xpath->query('td[1]/a/img', $element) as $image) {
                 $imageUrl = 'http://www.nedgame.nl' . $image->getAttribute('src');
             }
             // Get link & title
             foreach ($xpath->query('td[2]/a', $element) as $link) {
                 $url = $link->getAttribute('href');
                 $title = $link->nodeValue;
             }
             // Get price
             foreach ($xpath->query('td[3]/div/div[4]', $element) as $prices) {
                 preg_match('/([0-9,\\-]+)/', $prices->nodeValue, $matches);
                 $price = $matches[0];
             }
             // Get platform
             foreach ($xpath->query('td[2]/span', $element) as $details) {
                 preg_match('/Platform: (.*)Type:/', $details->nodeValue, $matches);
                 $platform = $matches[1];
             }
             $results[] = array('title' => $title, 'url' => $url, 'img' => $imageUrl, 'platform' => $platform, 'price' => $price);
         }
         return $results;
     }
 }
开发者ID:mrpapercut,项目名称:gameshopsnl,代码行数:33,代码来源:Nedgame.class.php

示例11: parseXmlStream

function parseXmlStream($content, $field_mapping)
{
    $res = array();
    $xml = new DOMDocument();
    $xml->loadXML($content);
    $xpath = new DOMXpath($xml);
    $rootNamespace = $xml->lookupNamespaceUri($xml->namespaceURI);
    $xpath->registerNamespace('x', $rootNamespace);
    foreach ($field_mapping as $skey => $sval) {
        $path = preg_replace("/\\/([a-zA-Z])/", "/x:\$1", $skey);
        $elements = $xpath->query($path);
        if (!is_null($elements)) {
            $ele_cnt = 1;
            foreach ($elements as $element) {
                foreach ($sval as $field => $innerpath) {
                    $ipath = preg_replace(array("/^([a-zA-Z])/", "/\\/([a-zA-Z])/"), array("x:\$1", "/x:\$1"), $innerpath);
                    $val = $xpath->query($ipath, $element)->item(0)->textContent;
                    if ($val) {
                        $field_details = explode(':', $field);
                        $res[$field_details[0]][$ele_cnt][$field_details[1]] = $val;
                    }
                }
                $ele_cnt++;
            }
        }
    }
    return $res;
}
开发者ID:katopenzz,项目名称:openemr,代码行数:28,代码来源:parse_patient_xml.php

示例12: array

 function get_play_store()
 {
     $remote = array();
     $store_page = new DOMDocument();
     $internalErrors = libxml_use_internal_errors(true);
     $store_page->loadHTMLFile("https://play.google.com/store/search?q=awareframework%20plugin");
     $xpath = new DOMXpath($store_page);
     $packages_titles = $xpath->query('//a[@class="title"]/@href');
     foreach ($packages_titles as $pkgs) {
         $package_name = substr($pkgs->textContent, strrpos($pkgs->textContent, "=") + 1, strlen($pkgs->textContent));
         preg_match("/^com\\.aware\\.plugin\\..*/", $package_name, $matches, PREG_OFFSET_CAPTURE);
         if (count($matches) == 0) {
             continue;
         }
         $package_page = new DOMDocument();
         $package_page->loadHTMLFile("https://play.google.com/store/apps/details?id={$package_name}");
         $xpath = new DOMXpath($package_page);
         $icon = $xpath->query('//img[@class="cover-image"]/@src');
         $version = $xpath->query('//div[@itemprop="softwareVersion"]');
         $description = $xpath->query('//div[@itemprop="description"]');
         $pkg = array('title' => trim($pkgs->parentNode->textContent), 'package' => $package_name, 'version' => trim($version->item(0)->textContent), 'desc' => $description->item(0)->childNodes->item(1)->nodeValue, 'iconpath' => 'https:' . $icon->item(0)->value, 'first_name' => 'AWARE', 'last_name' => 'Framework', 'email' => 'aware@comag.oulu.fi');
         $remote[] = $pkg;
     }
     return $remote;
 }
开发者ID:denzilferreira,项目名称:aware-server,代码行数:25,代码来源:plugins_model.php

示例13: getForm

 public function getForm($formId, $params, $headers)
 {
     /** @var DOMElement $form */
     $dom = new DomDocument();
     libxml_use_internal_errors(true);
     $dom->loadHTML($this->response());
     $xpath = new DOMXpath($dom);
     $form = $xpath->query("//form[@id='{$formId}']")->item(0);
     $elements = $xpath->query('//input');
     $form_params = [];
     $allowedTypes = ["hidden", "text", "password"];
     foreach ($elements as $element) {
         /** @var DOMElement $element */
         $type = $element->getAttribute("type");
         if (in_array($type, $allowedTypes)) {
             $name = $element->getAttribute("name");
             $value = $element->getAttribute("value");
             $form_params[$name] = $value;
         }
     }
     $headers = array_merge(["Referer" => $this->baseUri], $headers);
     $url = Uri::resolve(new Uri($this->baseUri), $form->getAttribute("action"))->__toString();
     $method = strtoupper($form->getAttribute("method"));
     return ["method" => $method, "url" => $url, "headers" => $headers, "params" => array_merge($form_params, $params)];
 }
开发者ID:ifgroup,项目名称:browser,代码行数:25,代码来源:Browser.php

示例14: getRemoteId

 /**
  * @return string
  */
 public function getRemoteId()
 {
     $videoIdNode = $this->xpath->query("//*/item_status/id[@type='video_id']")->item(0);
     if (is_null($videoIdNode)) {
         return null;
     }
     return $videoIdNode->nodeValue;
 }
开发者ID:DBezemer,项目名称:server,代码行数:11,代码来源:MsnDistributionStatusParser.php

示例15: getVideoId

 public function getVideoId()
 {
     $reference = $this->xpath->query("//*/id[@type='Video ID']")->item(0);
     if ($reference) {
         return $reference->nodeValue;
     }
     return null;
 }
开发者ID:DBezemer,项目名称:server,代码行数:8,代码来源:YouTubeDistributionRightsFeedLegacyStatusParser.php


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