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


PHP domDocument::loadHTMLFile方法代码示例

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


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

示例1: readhtml

 function readhtml()
 {
     $dom = new domDocument();
     $dom->loadHTMLFile("docs/KUNNAMKUL.html");
     $dom->preserveWhiteSpace = false;
     $tables = $dom->getElementsByTagName('table');
     /*** get all rows from the table ***/
     $rows = $tables->item(0)->getElementsByTagName('tr');
     /*** loop over the table rows ***/
     $dataArray = array();
     foreach ($rows as $row) {
         /*** get each column by tag name ***/
         $cols = $row->getElementsByTagName('td');
         /*** echo the values ***/
         if ($cols->item(0)->nodeValue) {
             $tmpArray = array();
             $tmpArray[] = $cols->item(0)->nodeValue;
             $name = $cols->item(1)->getElementsByTagName('p');
             $tmpArray[] = $name->item(0)->nodeValue;
             $tmpstring = isset($name->item(1)->nodeValue) ? $name->item(1)->nodeValue : '';
             $tmpstring .= isset($name->item(2)->nodeValue) ? $name->item(2)->nodeValue : '';
             $tmpstring .= isset($name->item(3)->nodeValue) ? $name->item(3)->nodeValue : '';
             $tmpArray[] .= $tmpstring;
             //$tmpArray[]=$cols->item(1)->nodeValue;
             $bsdob = $cols->item(2)->getElementsByTagName('p');
             $tmpArray[] = $bsdob->item(0)->nodeValue;
             $tmpArray[] = isset($bsdob->item(1)->nodeValue) ? $bsdob->item(1)->nodeValue : '';
             $tmpArray[] = isset($bsdob->item(2)->nodeValue) ? $bsdob->item(2)->nodeValue : '';
             //$tmpArray[]=$bsdob->item(2)->nodeValue;
             $factorinfo = $cols->item(3)->getElementsByTagName('p');
             $tmpArray[] = isset($factorinfo->item(0)->nodeValue) ? $factorinfo->item(0)->nodeValue : '';
             $tmpArray[] = isset($factorinfo->item(1)->nodeValue) ? $factorinfo->item(1)->nodeValue : '';
             $dpan = $cols->item(4)->getElementsByTagName('p');
             $tmpArray[] = $dpan->item(0)->nodeValue;
             $tmpArray[] = isset($dpan->item(1)->nodeValue) ? $dpan->item(1)->nodeValue : '';
             $tmpArray[] = isset($dpan->item(2)->nodeValue) ? $dpan->item(2)->nodeValue : '';
             $dataArray[] = $tmpArray;
         }
     }
     $this->load->library('table');
     $tmpl = array('table_open' => '<table border="1" cellpadding="2" cellspacing="1" class="mytable">');
     $this->table->set_template($tmpl);
     echo $this->table->generate($dataArray);
 }
开发者ID:JosephMokano,项目名称:somu-nhr,代码行数:44,代码来源:nhrtools1.php

示例2: loadIntoExisting

 /**
  * Loads PHPExcel from file into PHPExcel instance
  *
  * @param 	string 		$pFilename
  * @param	PHPExcel	$objPHPExcel
  * @return 	PHPExcel
  * @throws 	Exception
  */
 public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
 {
     // Check if file exists
     if (!file_exists($pFilename)) {
         throw new Exception("Could not open " . $pFilename . " for reading! File does not exist.");
     }
     // Create new PHPExcel
     while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
         $objPHPExcel->createSheet();
     }
     $objPHPExcel->setActiveSheetIndex($this->_sheetIndex);
     //	Create a new DOM object
     $dom = new domDocument();
     //	Load the HTML file into the DOM object
     $loaded = $dom->loadHTMLFile($pFilename);
     if ($loaded === false) {
         throw new Exception('Failed to load ', $pFilename, ' as a DOM Document');
     }
     //	Discard white space
     $dom->preserveWhiteSpace = false;
     $row = 0;
     $column = 'A';
     $content = '';
     $this->_processDomElement($dom, $objPHPExcel->getActiveSheet(), $row, $column, $content);
     echo '<hr />';
     var_dump($this->_dataArray);
     // Return
     return $objPHPExcel;
 }
开发者ID:bouras20122012,项目名称:hack4europe3d,代码行数:37,代码来源:HTML.php

示例3: loadIntoExisting

 /**
  * Loads PHPExcel from file into PHPExcel instance
  *
  * @param 	string 		$pFilename
  * @param	PHPExcel	$objPHPExcel
  * @return 	PHPExcel
  * @throws 	PHPExcel_Reader_Exception
  */
 public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel)
 {
     // Open file to validate
     $this->_openFile($pFilename);
     if (!$this->_isValidFormat()) {
         fclose($this->_fileHandle);
         throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file.");
     }
     //	Close after validating
     fclose($this->_fileHandle);
     // Create new PHPExcel
     while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
         $objPHPExcel->createSheet();
     }
     $objPHPExcel->setActiveSheetIndex($this->_sheetIndex);
     //	Create a new DOM object
     $dom = new domDocument();
     //	Reload the HTML file into the DOM object
     $loaded = $dom->loadHTMLFile($pFilename);
     if ($loaded === FALSE) {
         throw new PHPExcel_Reader_Exception('Failed to load ', $pFilename, ' as a DOM Document');
     }
     //	Discard white space
     $dom->preserveWhiteSpace = false;
     $row = 0;
     $column = 'A';
     $content = '';
     $this->_processDomElement($dom, $objPHPExcel->getActiveSheet(), $row, $column, $content);
     //		echo '<hr />';
     //		var_dump($this->_dataArray);
     // Return
     return $objPHPExcel;
 }
开发者ID:agashish,项目名称:test_new,代码行数:41,代码来源:HTML.php

示例4: _importFeaturedImage

 /**
  * Import Featured Image from Posts
  *
  * @param mixed $settings Array of settings
  * @param string $postUrl Url of WordPress post
  * @param string $baseUrl domain and uri path to Wordpress site
  *
  * @return string $postContent Post content with image url attributes updated.
  */
 private function _importFeaturedImage($settings, $postUrl, $baseUrl)
 {
     // Scrape post for featured image
     $tempFileName = md5($postUrl) . '.tmp';
     $tempFolder = craft()->path->getStoragePath() . 'instablog/';
     $tempFile = $tempFolder . $tempFileName;
     $postUrl = $this->_getAbsoluteUrl($postUrl, $baseUrl);
     $curlResponse = $this->_getRemoteFile($postUrl, $tempFile);
     $remoteImagePath = false;
     if ($curlResponse && false === IOHelper::isFileEmpty($tempFile, true)) {
         $dom = new \domDocument();
         // load the html into the object
         $dom->loadHTMLFile($tempFile);
         $dom->preserveWhiteSpace = false;
         $imgEls = $dom->getElementsByTagName('img');
         foreach ($imgEls as $img) {
             if (strpos($img->getAttribute('class'), 'wp-post-image')) {
                 $remoteImagePath = $img->getAttribute('src');
             }
         }
         IOHelper::deleteFile($tempFile, true);
     }
     // Add asset
     if ($remoteImagePath) {
         if ($assetId = $this->_addAsset($settings, $remoteImagePath, $baseUrl, false)) {
             return $assetId;
         }
     }
     return false;
 }
开发者ID:lukeholder,项目名称:craft-instablog,代码行数:39,代码来源:InstaBlog_ImportService.php

示例5: loadIntoExisting

    /**
     * Loads PHPExcel from file into PHPExcel instance
     *
     * @param   string      $pFilename
     * @param   PHPExcel    $objPHPExcel
     * @return  PHPExcel
     * @throws  PHPExcel_Reader_Exception
     */
    public function loadIntoExisting($pFilename, PHPExcel $objPHPExcel, $isString = false)
    {

        $isHtmlFile = FALSE;

        // Check if it's a string or file
        if(!$isString)
        {
            // Double check if it's a file
            if(is_file($pFilename)){
               $isHtmlFile = TRUE;
               // Open file to validate
               $this->_openFile($pFilename);

               if (!$this->_isValidFormat()) {
                 fclose ($this->_fileHandle);
                 throw new PHPExcel_Reader_Exception($pFilename . " is an Invalid HTML file.");
               }

                fclose ($this->_fileHandle);
            }
        }

        // Create new PHPExcel
        while ($objPHPExcel->getSheetCount() <= $this->_sheetIndex) {
            $objPHPExcel->createSheet();
        }
        $objPHPExcel->setActiveSheetIndex( $this->_sheetIndex );

        //  Create a new DOM object
        $dom = new \domDocument;
        //  Reload the HTML file into the DOM object

        // Check if we need to load the file or the HTML
        if($isHtmlFile)
        {
            // Load HTML from file
            $loaded = $dom->loadHTMLFile($pFilename);
        }
        else
        {
            // Load HTML from string
            $loaded = @$dom->loadHTML(mb_convert_encoding($pFilename, 'HTML-ENTITIES', 'UTF-8'));
        }

        if ($loaded === FALSE) {
            throw new \PHPExcel_Reader_Exception('Failed to load ',$pFilename,' as a DOM Document');
        }

        //  Discard white space
        $dom->preserveWhiteSpace = true;


        $row = 0;
        $column = 'A';
        $content = '';
        $this->_processDomElement($dom,$objPHPExcel->getActiveSheet(),$row,$column,$content);
        $this->autosizeColumn($objPHPExcel);

        return $objPHPExcel;
    }
开发者ID:hendryguna,项目名称:laravel-basic,代码行数:69,代码来源:HTML_reader.php

示例6: domDocument

		</div>
		<div class="section">
			<div class="container">
                <div class="row">
                    <div class="col-md-4"></div>
                    <div class="col-md-4">
                        <div class="well well-lg">
							<?php 
// This is the file path to be uploaded.
$inputFileName = 'classlist.htm';
//$myfile = fopen("classlist.htm", "r") or die("Unable to open file!");
libxml_use_internal_errors(true);
// a new dom object
$dom = new domDocument();
try {
    $dom->loadHTMLFile("classlist.htm");
} catch (Exception $e) {
    die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
}
$dom->preserveWhiteSpace = false;
$firstRow = 1;
$rows = $dom->getElementsByTagName("tr");
if (!is_null($rows)) {
    // Go through each row one by one
    foreach ($rows as $row) {
        if ($firstRow == 0) {
            $id = $row->childNodes->item(0)->textContent;
            $fullName = $row->childNodes->item(2)->textContent;
            $email = strtolower($row->childNodes->item(4)->textContent);
            // Split the name into last name, first name
            $commaPosition = strpos($fullName, ',');
开发者ID:kamaltmo,项目名称:N.E.L.L.,代码行数:31,代码来源:convertClasslist.php

示例7: XSLTProcessor

<?php

//header("Content-type:text/xml");
$dom = domDocument::loadHTMLFile($_GET["file"]);
$xslt = domDocument::load("style.xslt");
$proc = new XSLTProcessor();
$proc->importStylesheet($xslt);
$html = $proc->transformToDoc($dom);
echo $html->saveXML();
开发者ID:robotnic,项目名称:khtmlib,代码行数:9,代码来源:showsrc.php

示例8: importFile

 public static function importFile($file)
 {
     libxml_use_internal_errors(true);
     $dom = new domDocument();
     $dom->loadHTMLFile($file);
     $links = $dom->getElementsByTagName('a');
     OCP\DB::beginTransaction();
     foreach ($links as $link) {
         $title = $link->nodeValue;
         $ref = $link->getAttribute("href");
         $tag_str = '';
         if ($link->hasAttribute("tags")) {
             $tag_str = $link->getAttribute("tags");
         }
         $tags = explode(',', $tag_str);
         $desc_str = '';
         if ($link->hasAttribute("description")) {
             $desc_str = $link->getAttribute("description");
         }
         self::addBookmark($ref, $title, $tags, $desc_str);
     }
     OCP\DB::commit();
     return array();
 }
开发者ID:droiter,项目名称:openwrt-on-android,代码行数:24,代码来源:bookmarks.php

示例9: importFile

 /**
  * @brief Import Bookmarks from html formatted file
  * @param $user User imported Bookmarks should belong to
  * @param IDb $db Database Interface
  * @param $file Content to import
  * @return null
  * */
 public static function importFile($user, IDb $db, $file)
 {
     libxml_use_internal_errors(true);
     $dom = new \domDocument();
     $dom->loadHTMLFile($file);
     $links = $dom->getElementsByTagName('a');
     // Reintroduce transaction here!?
     foreach ($links as $link) {
         $title = $link->nodeValue;
         $ref = $link->getAttribute("href");
         $tag_str = '';
         if ($link->hasAttribute("tags")) {
             $tag_str = $link->getAttribute("tags");
         }
         $tags = explode(',', $tag_str);
         $desc_str = '';
         if ($link->hasAttribute("description")) {
             $desc_str = $link->getAttribute("description");
         }
         self::addBookmark($user, $db, $ref, $title, $tags, $desc_str);
     }
     return array();
 }
开发者ID:woodworker,项目名称:bookmarks,代码行数:30,代码来源:bookmarks.php


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