• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP DOMXpath类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了DOMXpath类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: hasSignificantWhitespace

 /**
  * Returns if significant whitespaces occur in the paragraph.
  *
  * This method checks if the paragraph $element contains significant
  * whitespaces in form of <text:s/> or <text:tab/> elements.
  * 
  * @param DOMElement $element 
  * @return bool
  */
 protected function hasSignificantWhitespace(DOMElement $element)
 {
     $xpath = new DOMXpath($element->ownerDocument);
     $xpath->registerNamespace('text', ezcDocumentOdt::NS_ODT_TEXT);
     $whitespaces = $xpath->evaluate('.//text:s|.//text:tab|.//text:line-break', $element);
     return $whitespaces instanceof DOMNodeList && $whitespaces->length > 0;
 }
开发者ID:axelmdev,项目名称:ecommerce,代码行数:16,代码来源:paragraph.php


示例3: 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


示例4: rerender

 /**
  * 
  */
 public function rerender()
 {
     $cssFileContent = '';
     $components = $this->uiComposer->getUiComponents();
     //Get all CSS file content
     foreach ($components as $component) {
         //TODO: check renderresult instead of component type
         if ($component instanceof HtmlWidget) {
             $cssFileContent .= $component->getRenderResult()->cssFileContent;
         }
     }
     if (trim($cssFileContent)) {
         // build file
         $cssFileContent = $this->minify($cssFileContent);
         $httpFileNamePath = '/generated/' . md5($cssFileContent) . '.css';
         $fileNamePath = 'public' . $httpFileNamePath;
         if (!file_exists($fileNamePath)) {
             file_put_contents($fileNamePath, $cssFileContent);
         }
         // get $doc and add the href
         $doc = $this->uiComposer->getDoc();
         //TODO: use composer xpath?
         $xPath = new \DOMXpath($this->uiComposer->getDoc());
         $linkElement = $xPath->query('//link[@id="css-file"]');
         //TODO url function missing
         $linkElement->item(0)->setAttribute('href', FC::assetLink($httpFileNamePath));
     }
     $this->needsRerender = false;
 }
开发者ID:pkamps,项目名称:basexms,代码行数:32,代码来源:CssFile.php


示例5: HTMLtoLunchArray

 protected function HTMLtoLunchArray($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $xpath = new DOMXpath($doc);
     $dElements = array(0 => array(1), 1 => array(2), 2 => array(3), 3 => array(4), 4 => array(5));
     $arr = array();
     foreach ($dElements as $dId => $dArr) {
         $dayMenu = '';
         foreach ($dArr as $dRow) {
             $element = $xpath->query('/html/body/div[2]/div[2]/article/div/div/p[' . $dRow . ']');
             foreach ($element as $e) {
                 $dayMenuExploded = explode(PHP_EOL, $e->nodeValue);
                 $foodArray = array();
                 foreach ($dayMenuExploded as $foods) {
                     $foods = parent::cleanStr($foods);
                     if (!empty($foods)) {
                         $foodArray[] = preg_replace('/([\\t0-9, ]+$)/', '', $foods);
                     }
                 }
                 $dayMenu = implode(' / ', $foodArray);
             }
         }
         $weekDay = parent::weekNumToText($dId);
         $arr[$weekDay] = parent::fixSpaces(preg_replace('/[0-9, ]+$/', '', $dayMenu));
     }
     if (!empty($arr)) {
         return $arr;
     }
     return false;
 }
开发者ID:Kaapelikala,项目名称:lunchfetcher,代码行数:31,代码来源:FunkyBurger.php


示例6: populate_resource

 function populate_resource($id, $overrideExportable = false)
 {
     //local SOLR index for fast searching
     $ci =& get_instance();
     $ci->load->library('solr');
     $ci->solr->clearOpt('fq');
     $ci->solr->setOpt('fq', '+id:' . $id);
     $this->overrideExportable = $overrideExportable;
     $result = $ci->solr->executeSearch(true);
     if (sizeof($result['response']['docs']) == 1) {
         $this->index = $result['response']['docs'][0];
     }
     //local XML resource
     $xml = $this->ro->getSimpleXML();
     $xml = addXMLDeclarationUTF8($xml->registryObject ? $xml->registryObject->asXML() : $xml->asXML());
     $xml = simplexml_load_string($xml);
     $xml = simplexml_load_string(addXMLDeclarationUTF8($xml->asXML()));
     if ($xml) {
         $this->xml = $xml;
         $rifDom = new DOMDocument();
         $rifDom->loadXML($this->ro->getRif());
         $gXPath = new DOMXpath($rifDom);
         $gXPath->registerNamespace('ro', 'http://ands.org.au/standards/rif-cs/registryObjects');
         $this->gXPath = $gXPath;
     }
 }
开发者ID:aaryani,项目名称:RD-Switchboard-Net,代码行数:26,代码来源:dci.php


示例7: HTMLtoLunchArray

 /**
  * @param string $html HTML document
  * @return boolean|array
  */
 public function HTMLtoLunchArray($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $xpath = new DOMXpath($doc);
     $dElements = array(0 => array(2, 3, 4));
     $arr = array();
     foreach ($dElements as $dId => $dArr) {
         $dayMenu = array();
         foreach ($dArr as $dRow) {
             $element = $xpath->query('/html/body/div[2]/div/div/div/div/div[' . $dRow . ']/div[1]');
             foreach ($element as $e) {
                 $dish = ucfirst(strtolower(parent::cleanStr(utf8_decode(parent::fixSpaces(trim($e->nodeValue))))));
                 $dish = preg_replace('/\\([a-z, ]+\\)/e', 'strtoupper("$0")', $dish);
                 $dayMenu[] = $dish;
             }
         }
         $weekDay = parent::today();
         $arr[$weekDay] = implode(' / ', $dayMenu);
     }
     if (!empty($arr)) {
         return $arr;
     }
     return false;
 }
开发者ID:jka0,项目名称:lunchfetcher,代码行数:29,代码来源:KarlJohan.php


示例8: 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


示例9: process

 function process(&$article)
 {
     $owner_uid = $article["owner_uid"];
     if (strpos($article["link"], "threewordphrase.com") !== FALSE) {
         if (strpos($article["plugin_data"], "af_comics,{$owner_uid}:") === FALSE) {
             $doc = new DOMDocument();
             @$doc->loadHTML(fetch_file_contents($article["link"]));
             $basenode = false;
             if ($doc) {
                 $xpath = new DOMXpath($doc);
                 $basenode = $xpath->query("//td/center/img")->item(0);
                 if ($basenode) {
                     $article["content"] = $doc->saveXML($basenode);
                     $article["plugin_data"] = "af_comics,{$owner_uid}:" . $article["plugin_data"];
                 }
             }
         } else {
             if (isset($article["stored"]["content"])) {
                 $article["content"] = $article["stored"]["content"];
             }
         }
         return true;
     }
     return false;
 }
开发者ID:neynah,项目名称:Tiny-Tiny-RSS,代码行数:25,代码来源:af_comics_twp.php


示例10: get_image

function get_image($game, $name, $width, $height)
{
    $url = 'http://steamcommunity.com/market/listings/' . $game . '/' . rawurlencode($name) . '/render?start=0&count=1&currency=1&format=json';
    $response = get_page_html($url);
    $jobject = json_decode($response);
    if (!isset($jobject)) {
        return null;
    }
    // Get the HTML render
    $render_html = $jobject->results_html;
    // Parse the html
    $dom = new DOMDocument();
    $dom->loadHTML($render_html);
    $xpath = new DOMXpath($dom);
    // Get the image
    $img = $xpath->query('//img[@class="market_listing_item_img"]')->item(0);
    if (!isset($img)) {
        return null;
    }
    // Get image src
    $imgurl = $img->getAttribute('src');
    // Remove the pre-set size
    $imgurl = substr($imgurl, 0, strrpos($imgurl, '/'));
    // Replace with our size
    $imgurl .= '/' . $width . 'fx' . $height . 'f';
    return $imgurl;
}
开发者ID:Tyrrrz,项目名称:WPSteamMarketExcerpt,代码行数:27,代码来源:steam-market-excerpt.php


示例11: provideCategoryNameNodes

    /**
     * Provide DOMNodeLists of CategoryLink/Name nodes and a collection of categories.
     *
     * @return array[]
     */
    public function provideCategoryNameNodes()
    {
        $doc = Mage::helper('eb2ccore')->getNewDomDocument();
        $doc->loadXML('
			<CategoryLinks>
				<CategoryLink import_mode="Update">
					<Name>Luma Root</Name>
				</CategoryLink>
				<CategoryLink import_mode="Update">
					<Name>Luma Root-Shoes</Name>
				</CategoryLink>
				<CategoryLink import_mode="Update">
					<Name>Luma Root-Shoes-Boots</Name>
				</CategoryLink>
				<!-- The item should end up in Luma Root/Outerwear/Jackets, but not Luma Root/Outerwear -->
				<CategoryLink import_mode="Update">
					<Name>Luma Root-Outerwear-Jackets</Name>
				</CategoryLink>
			</CategoryLinks>
		');
        $xp = new DOMXpath($doc);
        $nodes = $xp->query('/CategoryLinks/CategoryLink[@import_mode!="Delete"]/Name');
        $catCol = $this->getResourceModelMockBuilder('catalog/category_collection')->setMethods(array('addAttributeToSelect', 'getColumnValues', 'getAllIds'))->getMock();
        $catCol->expects($this->any())->method('addAttributeToSelect')->with($this->identicalTo(array('name', 'path', 'id')))->will($this->returnSelf());
        $ids = array(0, 1, 2, 3, 30, 31);
        $names = array('Root Catalog', 'Luma Root', 'Shoes', 'Boots', 'Outerwear', 'Jackets');
        $paths = array('0', '0/1', '0/1/2', '0/1/2/3', '0/1/30', '0/1/30/31');
        $catCol->expects($this->any())->method('getColumnValues')->will($this->returnValueMap(array(array('name', $names), array('path', $paths))));
        $catCol->expects($this->any())->method('getAllIds')->will($this->returnValue($ids));
        return array(array($nodes, $catCol));
    }
开发者ID:sirishreddyg,项目名称:magento-retail-order-management,代码行数:36,代码来源:CategoryTest.php


示例12: count_quotations

function count_quotations($html)
{
    /* Count the number of quotations using the 'cite' tag
     * (Used to determine if URL should be submitted to Neotext)
     *
     * Credit: http://htmlparsing.com/php.html
     */
    $quotations_count = 0;
    # Parse the HTML
    # The @ before the method call suppresses any warnings that
    # loadHTML might throw because of invalid HTML in the page.
    $dom = new DOMDocument();
    @$dom->loadHTML($html);
    $xpath = new DOMXpath($dom);
    # Iterate over all the <blockquote> and <q> tags
    $quotations = $xpath->query('//blockquote | //q');
    //foreach($dom->getElementsByTagName('blockquote') as $quote) {
    foreach ($quotations as $quote) {
        $cite_url = $quote->getAttribute('cite');
        // If URL in valid form:
        if (!filter_var($cite_url, FILTER_VALIDATE_URL) === false) {
            $quotations_count = $quotations_count + 1;
        }
    }
    return $quotations_count;
}
开发者ID:neotext,项目名称:neotext-wordpress,代码行数:26,代码来源:quote-context.php


示例13: testOff

 function testOff()
 {
     $doc = $this->process_post("[bibshow file=custom://data show_links=0][bibcite key=test]", ShowLinks::$data);
     $xpath = new DOMXpath($doc);
     $href = $xpath->evaluate("//a[@class = 'papercite_bibcite']/@href");
     $this->assertEquals(0, $href->length, "There were {$href->length} links detected - expected none");
 }
开发者ID:t-artistik,项目名称:papercite,代码行数:7,代码来源:test-show_links.php


示例14: 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


示例15: indexAction

 public function indexAction()
 {
     SxCms_Acl::requireAcl('ad', 'ad.edit');
     $filename = APPLICATION_PATH . '/var/ads.xml';
     $dom = new DOMDocument();
     $dom->preserveWhiteSpace = false;
     $dom->loadXml(file_get_contents($filename));
     $dom->formatOutput = true;
     $xpath = new DOMXpath($dom);
     $xml = simplexml_import_dom($dom);
     if ($this->getRequest()->isPost()) {
         $ads = $this->_getParam('ad');
         foreach ($ads as $key => $value) {
             $nodeList = $xpath->query("//zone[id='{$key}']/content");
             if ($nodeList->length) {
                 $cdata = $dom->createCDATASection(stripslashes($value));
                 $content = $dom->createElement('content');
                 $content->appendChild($cdata);
                 $nodeList->item(0)->parentNode->replaceChild($content, $nodeList->item(0));
             }
         }
         $dom->save($filename);
         $flashMessenger = $this->_helper->getHelper('FlashMessenger');
         $flashMessenger->addMessage('Advertentie werd succesvol aangepast');
     }
     $this->view->ads = $xml;
 }
开发者ID:sonvq,项目名称:2015_freelance6,代码行数:27,代码来源:AdController.php


示例16: HTMLtoLunchArray

 /**
  * @param string $html HTML document
  * @return boolean|array
  */
 public function HTMLtoLunchArray($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $xpath = new DOMXpath($doc);
     $dElements = array(0 => array(2, 3, 4), 1 => array(8, 9, 10), 2 => array(14, 15, 16), 3 => array(20, 21, 22), 4 => array(26, 27, 28));
     $arr = array();
     $i = 0;
     foreach ($dElements as $dId => $dArr) {
         $dayMenu = array();
         foreach ($dArr as $dRow) {
             $element = $xpath->query('//*[@id="lounaslistaTable"]/tr[' . $dRow . ']/td[1]');
             foreach ($element as $e) {
                 $dayMenu[] = trim($e->nodeValue);
             }
         }
         $weekDay = parent::weekNumToText($i);
         $arr[$weekDay] = parent::fixSpaces(trim(implode(' / ', $dayMenu)));
         $i++;
     }
     if (!empty($arr)) {
         return $arr;
     }
     return false;
 }
开发者ID:jka0,项目名称:lunchfetcher,代码行数:29,代码来源:Harald.php


示例17: 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


示例18: HTMLtoLunchArray

 /**
  * @param string $html HTML document
  * @return boolean|array
  */
 public function HTMLtoLunchArray($html)
 {
     $doc = new DOMDocument();
     @$doc->loadHTML($html);
     $xpath = new DOMXpath($doc);
     $elements = $xpath->query('//*[@id="o-learys-forum-helsinki"]');
     $i = 0;
     $arr = array();
     foreach ($elements as $element) {
         $nodes = $element->childNodes;
         foreach ($nodes as $node) {
             $htmlString = $doc->saveHTML($node);
             if (preg_match('/<strong>O\'Learys Forum Helsinki<\\/strong>/', $htmlString)) {
                 preg_match_all("/<strong>([a-zA-Z]+) [0-9\\. ]+<\\/strong> <p>([a-zA-Z0-9\\’\\'\\,\\.\\-\\_\\)\\(äöÄÖ ]+)10€/", $htmlString, $res);
                 if (isset($res[2])) {
                     foreach ($res[2] as $result) {
                         $weekDay = parent::weekNumToText($i);
                         $arr[$weekDay] = $result;
                         $i++;
                     }
                 }
             }
         }
     }
     if (empty($arr)) {
         return false;
     }
     return $arr;
 }
开发者ID:jka0,项目名称:lunchfetcher,代码行数:33,代码来源:Olearys.php


示例19: hal_parse

function hal_parse($url)
{
    $url = trim(html_entity_decode($url), "\"' ");
    $infos = parse_url($url);
    $ip = gethostbyname($infos['host']);
    if ($ip != '193.48.96.10') {
        spip_log("Url invalid", _LOG_ERREUR);
        return;
    }
    spip_log(sprintf("[hal_parse] init_http(%s)", $url), _LOG_DEBUG);
    $content = recuperer_page($url);
    spip_log(sprintf("[hal_parse] init_http(%s): Done", $url), _LOG_DEBUG);
    $dom = new DomDocument('1.0', 'UTF-8');
    $dom->preserveWhiteSpace = false;
    $str = mb_convert_encoding($content, "HTML-ENTITIES");
    @$dom->loadHTML($str);
    $xpath = new DOMXpath($dom);
    $entries = $xpath->query('//div[@id="res_script"]');
    if ($entries->length == 0) {
        spip_log("No tag found ...", _LOG_ERREUR);
        return;
    }
    $res_script = $dom->saveXML($entries->item(0));
    return $res_script;
}
开发者ID:RBoisselet,项目名称:spip_webpage_from_hal,代码行数:25,代码来源:webpage_from_hal_fonctions.php


示例20: load

 /**
  * {@inheritdoc}
  */
 public function load(ObjectManager $manager)
 {
     // get already stored countries
     $qb = $manager->createQueryBuilder();
     $qb->from(Country::class, 'c', 'c.code');
     $qb->select('c');
     $existingCountries = $qb->getQuery()->getResult();
     // load xml
     $file = dirname(__FILE__) . '/../countries.xml';
     $doc = new \DOMDocument();
     $doc->load($file);
     $xpath = new \DOMXpath($doc);
     $elements = $xpath->query('/Countries/Country');
     if (!is_null($elements)) {
         /** @var $element DOMNode */
         foreach ($elements as $element) {
             /** @var $child DOMNode */
             foreach ($element->childNodes as $child) {
                 if (isset($child->nodeName)) {
                     if ($child->nodeName == 'Name') {
                         $countryName = $child->nodeValue;
                     }
                     if ($child->nodeName == 'Code') {
                         $countryCode = $child->nodeValue;
                     }
                 }
             }
             $country = array_key_exists($countryCode, $existingCountries) ? $existingCountries[$countryCode] : new Country();
             $country->setName($countryName);
             $country->setCode($countryCode);
             $manager->persist($country);
         }
     }
     $manager->flush();
 }
开发者ID:sulu,项目名称:sulu,代码行数:38,代码来源:LoadCountries.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP DSC类代码示例发布时间:2022-05-23
下一篇:
PHP DOMXPath类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap