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

Services/Utilities/classes/class.ilCSVWriter.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 
00038 class ilCSVWriter
00039 {
00040         private $csv = '';
00041         private $separator = ',';
00042         private $delimiter = '"';
00043         private $new_line = "\n";
00044         private $doUTF8Decoding = false;
00045         
00046         private $first_entry = true;
00047         
00055         public function __construct()
00056         {
00057                 
00058         }
00066         public function setSeparator($a_sep)
00067         {
00068                 $this->separator = $a_sep;
00069         }
00070         
00078         public function setDelimiter($a_del)
00079         {
00080                 $this->delimiter = $a_del;
00081         }
00082         
00089         public function addRow()
00090         {
00091                 $this->csv .= $this->new_line;
00092                 $this->first_entry = true;
00093         }
00094         
00101         public function setDoUTF8Decoding($doUTF8Decoding) 
00102         {
00103                 $this->doUTF8Decoding = $doUTF8Decoding ? true : false;
00104         }
00105         
00113         public function addColumn($a_col)
00114         {
00115                 if(!$this->first_entry)
00116                 {
00117                         $this->csv .= $this->separator;
00118                 }
00119                 $this->csv .= $this->delimiter;
00120                 $this->csv .= $this->quote($a_col);
00121                 $this->csv .= $this->delimiter;
00122                 $this->first_entry = false;
00123         }
00124         
00132         public function getCSVString()
00133         {
00134                 return $this->csv;
00135         }
00136         
00145         private function quote($a_str)
00146         {
00147                 return str_replace($this->delimiter,$this->delimiter.$this->delimiter, ($this->doUTF8Decoding) ? utf8_decode( $a_str ) : $a_str);
00148         }
00149 }
00150 
00151 
00152 
00153 ?>

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