Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 ?>