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


PHP domDocument::loadHTML方法代码示例

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


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

示例1: findWspolrzedne

 public function findWspolrzedne($adres, $miasto)
 {
     $adresTrim = trim($adres);
     $adresReplaceSpace = str_replace(' ', '+', $adresTrim);
     $LettersToChange = array('ó', 'ż', 'ź', 'ś', 'ę', 'ą', 'ł', 'ń', 'ć');
     $LettersChanged = array('o', 'z', 'z', 's', 'e', 'a', 'l', 'n', 'c');
     $adresWithoutPolishLetters = str_replace($LettersToChange, $LettersChanged, $adresReplaceSpace);
     $curl1 = curl_init();
     curl_setopt($curl1, CURLOPT_URL, "http://www.zumi.pl/namapie.html?qt=&loc={$miasto}%2C+{$adresWithoutPolishLetters}&Submit=Szukaj&cId=&sId=");
     curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
     $stronaZumi = curl_exec($curl1);
     curl_close($curl1);
     $dom = new domDocument();
     @$dom->loadHTML($stronaZumi);
     $dom->preserveWhiteSpace = false;
     $szukana = array();
     $divs = $dom->getElementsByTagName('div');
     foreach ($divs as $div) {
         $script = $div->getElementsByTagName('script');
         $szukana[] = $script->item(0)->nodeValue;
     }
     foreach ($szukana as $text) {
         if (strpos($text, 'objDefLoc')) {
             $a = substr($text, -29);
             $letterToRemove = array(':', '"', 'y', 'x', '}');
             $wspolrzedne1 = str_replace($letterToRemove, '', $a);
             $poz = strpos($wspolrzedne1, ',');
             $dlugosc = substr($wspolrzedne1, $poz);
             $dlugosc = str_replace(',', '', $dlugosc);
             $szerokosc = substr($wspolrzedne1, 0, $poz);
             $wspolrzedne[] = "{$dlugosc},{$szerokosc}";
         }
     }
     return $wspolrzedne[0];
 }
开发者ID:Adeptus,项目名称:porownywarka,代码行数:35,代码来源:ParserWspolrzedne.php

示例2: fetch_data_from_html

function fetch_data_from_html($remote_page)
{
    // Returns an array of products and ratings
    $product_rating_arr = array();
    $html = get_html($remote_page);
    $dom = new domDocument();
    $dom->loadHTML($html);
    $dom->preserveWhiteSpace = false;
    $tables = $dom->getElementsByTagName('table');
    $table = $tables->item(0);
    $rows = $table->getElementsByTagName('tr');
    $i = 0;
    foreach ($rows as $row) {
        if ($i != 0) {
            $columns = $row->getElementsByTagName('td');
            $product = $columns->item(0)->textContent;
            $rating = $columns->item(1)->textContent;
            $image = $columns->item(2)->textContent;
            $var = $product . "__" . $image;
            $product_rating_arr[$var] = $rating;
        }
        $i += 1;
    }
    return $product_rating_arr;
}
开发者ID:sanjeedha,项目名称:Enterprise-Marketplace,代码行数:25,代码来源:TopratedProducts.php

示例3: getContent

 public function getContent($params = array())
 {
     $awsCachePath = CACHEPATH . "/aws.status.cxml";
     $data = array();
     $neededLocations = array();
     $services = array('Amazon Elastic Compute Cloud', 'Amazon Relational Database Service', 'Amazon Simple Storage Service');
     $compliance = array('us-east-1' => array('name' => 'NA_block', 'filter' => array('N. Virginia', 'US Standard')), 'us-west-1' => array('name' => 'NA_block', 'filter' => 'N. California'), 'us-west-2' => array('name' => 'NA_block', 'filter' => 'Oregon'), 'sa-east-1' => array('name' => 'SA_block', 'filter' => ''), 'eu-west-1' => array('name' => 'EU_block', 'filter' => ''), 'ap-southeast-1' => array('name' => 'AP_block', 'filter' => 'Singapore'), 'ap-southeast-2' => array('name' => 'AP_block', 'filter' => 'Sydney'), 'ap-northeast-1' => array('name' => 'AP_block', 'filter' => 'Tokyo'));
     if (empty($params['locations'])) {
         $neededLocations = $this->getUsedLocations();
         $params['locations'] = $neededLocations;
     } else {
         $neededLocations = $params['locations'];
     }
     if (file_exists($awsCachePath) && time() - filemtime($awsCachePath) < 3600) {
         clearstatcache();
         $time = filemtime($awsCachePath);
         $data = (array) json_decode(file_get_contents($awsCachePath));
     } else {
         $html = @file_get_contents('http://status.aws.amazon.com');
         if ($html) {
             $dom = new domDocument();
             $dom->validateOnParse = false;
             @$dom->loadHTML($html);
             $dom->preserveWhiteSpace = false;
             foreach ($compliance as $compKey => $compValue) {
                 $div = $dom->getElementById($compValue['name']);
                 $tables = $div->getElementsByTagName('table');
                 $rows = $tables->item(0)->getElementsByTagName('tr');
                 foreach ($rows as $row) {
                     $cols = $row->getElementsByTagName('td');
                     if (preg_match('/(.*)(' . implode('|', $services) . ')(.*)/', $cols->item(1)->nodeValue)) {
                         $regionFilter = $compValue['filter'];
                         if (is_array($compValue['filter'])) {
                             $regionFilter = implode('|', $compValue['filter']);
                         }
                         if (preg_match('/(.*)(' . $regionFilter . ')(.*)/', $cols->item(1)->nodeValue)) {
                             $img = '';
                             $message = '';
                             if ($cols->item(0)->getElementsByTagName('img')->item(0)->getAttribute('src') == 'images/status0.gif') {
                                 $img = 'normal.png';
                             } else {
                                 $img = 'disruption.png';
                                 $message = $cols->item(2)->nodeValue;
                             }
                             $data[$compKey][substr(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), 0, strpos(str_replace($services, array('EC2', 'RDS', 'S3'), $cols->item(1)->nodeValue), ' ('))] = array('img' => $img, 'status' => $cols->item(2)->nodeValue, 'message' => $message);
                             $data[$compKey]['locations'] = $compKey;
                         }
                     }
                 }
             }
             file_put_contents($awsCachePath, json_encode($data));
         }
     }
     $retval = array('locations' => json_encode($neededLocations));
     foreach ($neededLocations as $value) {
         $retval['data'][] = $data[$value];
     }
     return $retval;
 }
开发者ID:recipe,项目名称:scalr,代码行数:59,代码来源:Status.php

示例4: __construct

 public function __construct($html, $baseurl)
 {
     $doc = new domDocument();
     $doc->loadHTML($html);
     $this->body = $doc->getElementsByTagName('html')->item(0)->getElementsByTagName('body')->item(0);
     $this->lines = array();
     $this->line = (object) array('text' => '', 'wrap' => true, 'prefix' => "\n");
     $this->pre = 0;
     $this->indent = array();
     $this->baseurl = $baseurl;
     $this->links = array();
     $this->linkcount = 0;
 }
开发者ID:janaece,项目名称:globalclassroom4_clean,代码行数:13,代码来源:htmltotext.php

示例5: get_pre

function get_pre($url)
{
    $html = file_get_contents($url);
    // a new dom object
    $dom = new domDocument('1.0', 'utf-8');
    // load the html into the object ***/
    @$dom->loadHTML($html);
    //discard white space
    $dom->preserveWhiteSpace = false;
    $pre = $dom->getElementsByTagName('pre');
    //Get elements by desired tag.
    return htmlspecialchars($pre->item(0)->nodeValue);
}
开发者ID:henrytrager,项目名称:TPCrawler,代码行数:13,代码来源:crawler.php

示例6: prepareContent

 function prepareContent($content)
 {
     if (!$content) {
         return '';
     }
     $dom = new domDocument();
     $dom->loadHTML('<?xml encoding="UTF-8">' . $content);
     $images = $dom->getElementsByTagName('img');
     foreach ($images as $image) {
         $src = $image->getAttribute('src');
         $image->setAttribute('src', site_url($src));
     }
     return $dom->saveHTML();
 }
开发者ID:e-gob,项目名称:chilesinpapeleo-instituciones,代码行数:14,代码来源:htmlcontent_helper.php

示例7: domDocument

 function get_instituicao_cursos($cod_endereco, $cod_instituicao)
 {
     $html = file_get_contents('http://emec.mec.gov.br/emec/consulta-ies/listar-curso-endereco/d96957f455f6405d14c6542552b0f6eb/' . base64_encode($cod_instituicao) . '/aa547dc9e0377b562e2354d29f06085f/' . base64_encode($cod_endereco) . '/list/1000');
     include_once './src/simple_html_dom.php';
     $dom = new domDocument();
     @$dom->loadHTML($html);
     $dom->preserveWhiteSpace = false;
     $tables = $dom->getElementsByTagName('tbody');
     foreach ($tables as $row) {
         $cols = $row->getElementsByTagName('td');
         $array[] = preg_replace("/[^A-Za-z]/", "", $cols->item(0)->nodeValue);
     }
     return $array;
 }
开发者ID:alissonlinneker,项目名称:e-MEC-API,代码行数:14,代码来源:api.php

示例8: toRichTextObject

 public function toRichTextObject($html)
 {
     $this->initialise();
     //	Create a new DOM object
     $dom = new domDocument();
     //	Load the HTML file into the DOM object
     //  Note the use of error suppression, because typically this will be an html fragment, so not fully valid markup
     $loaded = @$dom->loadHTML($html);
     //	Discard excess white space
     $dom->preserveWhiteSpace = false;
     $this->richTextObject = new PHPExcel_RichText();
     $this->parseElements($dom);
     return $this->richTextObject;
 }
开发者ID:MyPHPTools,项目名称:PHPExcel,代码行数:14,代码来源:HTML.php

示例9: getSelectedItems

 /**
  * Extract selected items array from html multiselect tag
  *
  * @param array Html multiselect tag
  * @return array Selected items array
  */
 private function getSelectedItems($html)
 {
     $dom = new domDocument();
     $dom->loadHTML($html);
     $dom->preserveWhiteSpace = false;
     $options = $dom->getElementsByTagname('option');
     $items = array();
     foreach ($options as $option) {
         if ($option->hasAttribute('selected')) {
             $items[] = $option->nodeValue;
         }
     }
     return $items;
 }
开发者ID:kenners,项目名称:uamuzi-bora,代码行数:20,代码来源:multiselect.php

示例10: parseLicenseTbl

 /**
  * parseLicenseTbl
  * \brief given a fossology license histogram, parse it into license
  * names and Show links.
  *
  * @returns an array of associative arrays  with keys of:
  * count, showLink, textOrLink. the values will be the license count
  * the url of the Show link and whatever is in the next column.  This
  * can be text or a link or ?
  *
  * Sets property noRows.
  *
  * An empty array if no license histogram on that page,
  *
  */
 function parseLicenseTbl()
 {
     /*
      * Each table row has 3 td's in it. First is the license count, second
      * is the show link and third is the license name.
      */
     $dom = new domDocument();
     @$dom->loadHTML($this->page);
     /*** discard white space ***/
     $dom->preserveWhiteSpace = false;
     $table = $dom->getElementById($this->tableId);
     if (empty($table)) {
         $this->emptyTable = TRUE;
         //print "DPLTDB: table is empty, can't find table! with table id of:$this->tableId\n";
         return $this->hList = array();
     }
     foreach ($table->childNodes as $tblChildNode) {
         $histogram = array();
         foreach ($tblChildNode->childNodes as $childNode) {
             if ($childNode->nodeName == 'td') {
                 if (is_numeric($childNode->nodeValue)) {
                     $histogram['count'] = trim($childNode->nodeValue);
                 }
                 if ($childNode->nodeValue == 'Show') {
                     $anchorList = $childNode->getElementsByTagName('a');
                     foreach ($anchorList as $anchorEle) {
                         $histogram['showLink'] = $anchorEle->getAttribute('href');
                     }
                 }
                 if (is_string($childNode->nodeValue)) {
                     $histogram['textOrLink'] = trim($childNode->nodeValue);
                 }
             }
         }
         // foreach($tblChildNode
         $this->hList[] = $histogram;
         $histogram = array();
     }
     // foreach
     // for tables with titles, the first row is empty as no childNodes match
     // what we are looking for, remove the first row.
     if ($this->title) {
         // remove empty 1st entry
         unset($this->hList[0]);
     }
     if (empty($this->hList)) {
         $this->noRows = TRUE;
     }
 }
开发者ID:DanielDobre,项目名称:fossology,代码行数:64,代码来源:dom-parseLicenseTable.php

示例11: asSimpleXml

 private function asSimpleXml($str)
 {
     if (stripos($str, '<!DOCTYPE html') !== false) {
         // we've got to parse the html first
         $dom = new domDocument();
         // hack needed or else loadHTML won't work with utf-8:
         @$dom->loadHTML('<?xml encoding="UTF-8">' . $str);
         $simpleXmlObj = simplexml_import_dom($dom);
     } elseif (stripos($str, '<?xml') === 0) {
         $simpleXmlObj = simplexml_load_string($str);
     } else {
         throw new Exception("Can't parse as XML or HTML.");
     }
     return $simpleXmlObj;
 }
开发者ID:jdblischak,项目名称:plos_altmetrics_study,代码行数:15,代码来源:UrlGetter.php

示例12: parseTags

 private function parseTags($tag = '', $source = "")
 {
     if (!$tag) {
         throw new Exception\CrawlException('Tag has type of null');
     }
     /*** a new dom object ***/
     $dom = new \domDocument();
     @$dom->loadHTML($source);
     /*** remove silly white space ***/
     $dom->preserveWhiteSpace = false;
     /*** get the links from the HTML ***/
     //  $tag->setTag('a');
     $tags = $dom->getElementsByTagName($tag);
     return $tags;
 }
开发者ID:johnnymast,项目名称:redbox-crawl,代码行数:15,代码来源:Crawl.php

示例13: getTextBetweenTags

/**
 *
 * from http://www.phpro.org/examples/Get-Text-Between-Tags.html
 * 
 * @get text between tags
 * @param string $tag The tag name
 * @param string $html The XML or XHTML string
 * @param int $strict Whether to use strict mode
 * @return array
 *
 */
function getTextBetweenTags($tag, $html, $strict = 0)
{
    $dom = new domDocument();
    if ($strict == 1) {
        $dom->loadXML($html);
    } else {
        $dom->loadHTML($html);
    }
    $dom->preserveWhiteSpace = false;
    $content = $dom->getElementsByTagname($tag);
    $out = array();
    foreach ($content as $item) {
        $out[] = $item->nodeValue;
    }
    return $out;
}
开发者ID:slims,项目名称:s3st15_matoa,代码行数:27,代码来源:index_template.inc.php

示例14: getAllServers

    /**
     * This function returns an associative array containing information 
     * about every WoW Server. 
     *
     * The associative array is in the following format:
     * "name" - Name of the server. 
     * "status" - Status of the server ("up" or "down")
     * "type" - Type of server (PvE, PvP, RP)
     * "population" - Low, Medium, High server status. 
     * "locale" - Location of WoW Server (United States by default)
     */
    function getAllServers() {

        if($this->SERVER_ARRAY == null) {

            $dom = new domDocument;
            $dom->loadHTML(file_get_contents($this->STATUS_URL));
            $dom->preserveWhiteSpace = false;

            $xpath = new DOMXPath($dom);

            $name = $xpath->query('//td[@class="name"]');
            $status = $xpath->query('//td[@class="status"]/div/@class');
            $type = $xpath->query('//td[@class="type"]/span');
            $population = $xpath->query('//td[@class="population"]/span');
            $locale = $xpath->query('//td[@class="locale"]');

            /* Generate the number of servers */
            $ctr = 0;
            foreach($name as $n) {
                $ctr++;
            }

            $serverArray = array();

            for($i=0;$i<$ctr;$i++) {

                $s = explode(" ", trim($status->item($i)->nodeValue));

                $info = array (
                    "name" => trim(utf8_decode($name->item($i)->nodeValue)),
                    "status" => $s[1],
                    "type" => substr(substr(trim($type->item($i)->nodeValue),0,-1),1),
                    "population" => trim($population->item($i)->nodeValue),
                    "locale" => trim(utf8_decode($locale->item($i)->nodeValue))
                );

                array_push($serverArray, $info);
            }

            $this->SERVER_ARRAY = $serverArray;
        }

        return $this->SERVER_ARRAY;
    }
开发者ID:Gelatine,项目名称:WoWRealmStatus,代码行数:55,代码来源:RealmStatus.php

示例15: findMonitor

 public function findMonitor($szukana)
 {
     $curl1 = curl_init();
     curl_setopt($curl1, CURLOPT_URL, "http://www.samsung.com/pl/function/espsearch/searchResult.do?keywords={$szukana}&amp;input_keyword={$szukana}");
     curl_setopt($curl1, CURLOPT_RETURNTRANSFER, 1);
     $strona1 = curl_exec($curl1);
     curl_close($curl1);
     $dom1 = new domDocument();
     @$dom1->loadHTML($strona1);
     $dom1->preserveWhiteSpace = false;
     $nazwa = array();
     $a = $dom1->getElementsByTagName('a');
     foreach ($a as $a) {
         $class = $a->getAttribute('class');
         $href = $a->getAttribute('href');
         $nazwa[$class] = $href;
     }
     $nazwa2 = $nazwa['arrow_blue'];
     $url = "{$nazwa2}&tab=specification";
     $curl2 = curl_init();
     curl_setopt($curl2, CURLOPT_URL, "{$url}");
     curl_setopt($curl2, CURLOPT_RETURNTRANSFER, 1);
     $strona2 = curl_exec($curl2);
     curl_close($curl2);
     $tabela = array();
     $dom2 = new domDocument();
     @$dom2->loadHTML($strona2);
     $dom2->preserveWhiteSpace = false;
     $nazwa = $dom2->getElementsByTagName('h1');
     $tabela['nazwa'] = $nazwa->item(0)->nodeValue;
     $rows = $dom2->getElementsByTagName('tr');
     foreach ($rows as $row) {
         $th = $row->getElementsByTagName('th');
         $nazwa = $th->item(0)->nodeValue;
         $nazwa2 = $th->item(1)->nodeValue;
         $td = $row->getElementsByTagName('td');
         $wartosc = $td->item(0)->nodeValue;
         $tabela[trim($nazwa)] = trim($wartosc);
         $tabela[trim($nazwa2)] = trim($wartosc);
     }
     $correctTable = $this->removeAllWrongValueFromTable($tabela);
     return $correctTable;
 }
开发者ID:Adeptus,项目名称:porownywarka,代码行数:43,代码来源:ParserSamsung.php


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