Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 /**
  * 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;
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
 /**
  * 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;
 }
Ejemplo n.º 5
0
    /**
     * 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;
    }
Ejemplo n.º 6
0
		</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, ',');
Ejemplo n.º 7
0
<?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();
Ejemplo n.º 8
0
 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();
 }
Ejemplo n.º 9
0
 /**
  * @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();
 }