• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

Services/Utilities/classes/class.ilCSVReader.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2006 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00034 class ilCSVReader
00035 {
00036         private $ptr_file = null;
00037         private $data = array();
00038         private $separator = ';';       
00039         private $delimiter = '""';
00040         private $length = 1024; 
00041         
00049         public function __construct()
00050         {
00051                 
00052         }
00053         
00054         /*
00055          * Set Seperator
00056          *
00057          * @access public
00058          * @param string field seperator
00059          * 
00060          */
00061         public function setSeparator($a_sep)
00062         {
00063                 $this->separator = $a_sep;
00064         }
00065         
00073         public function setDelimiter($a_del)
00074         {
00075                 $this->delimiter = $a_del;
00076         }
00077         
00085         public function setLength($a_length)
00086         {
00087                 $this->length = $a_length;
00088         }
00089         
00090         public function open($file = "")
00091         {
00092                 return( $this->ptr_file = @fopen(ilUtil::stripSlashes($file), "r") );
00093         }       
00094         
00095         public function close()
00096         {
00097                 return( @fclose($this->ptr_file) );
00098         }
00099         
00107         public function getDataArrayFromCSVFile()
00108         {
00109                 $row = 0;
00110 
00111                 while (($line = fgetcsv($this->ptr_file, $this->length, $this->separator)) !== FALSE)
00112                 {
00113                         for ($col = 0; $col < count($line); $col++)
00114                         {
00115                                 $this->data[$row][$col] = $this->unquote($line[$col]);
00116                         }
00117                         
00118                         ++$row;
00119                 }
00120                 
00121                 return $this->data;
00122         }
00123         
00130         private function unquote($a_str)
00131         {
00132                 return str_replace($this->delimiter.$this->delimiter, $this->delimiter,$a_str);
00133         }
00134 }
00135 ?>

Generated on Fri Dec 13 2013 17:57:02 for ILIAS Release_3_9_x_branch .rev 46835 by  doxygen 1.7.1