ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
ilCSVWriter Class Reference

Helper class to generate CSV files. More...

+ Collaboration diagram for ilCSVWriter:

Public Member Functions

 __construct ()
 Constructor. More...
 
 setSeparator ($a_sep)
 Set Seperator. More...
 
 setDelimiter ($a_del)
 Set delimiter. More...
 
 addRow ()
 Add new line. More...
 
 setDoUTF8Decoding ($doUTF8Decoding)
 set to true if you want to utf8 decode for output. More...
 
 addColumn ($a_col)
 Add Column. More...
 
 getCSVString ()
 Get CSV string. More...
 

Private Member Functions

 quote ($a_str)
 Quote Delimiter by doubling it This seems to be the standard way in Excel and Openoffice. More...
 

Private Attributes

 $csv = ''
 
 $separator = ','
 
 $delimiter = '"'
 
 $new_line = "\n"
 
 $doUTF8Decoding = false
 
 $first_entry = true
 

Detailed Description

Helper class to generate CSV files.

Default field seperator is ',' Default string delimiter is '"' Multiple "-'s will be substituted with ""

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 38 of file class.ilCSVWriter.php.

Constructor & Destructor Documentation

◆ __construct()

ilCSVWriter::__construct ( )

Constructor.

public

Parameters

Definition at line 55 of file class.ilCSVWriter.php.

56  {
57  }

Member Function Documentation

◆ addColumn()

ilCSVWriter::addColumn (   $a_col)

Add Column.

Will be quoted automatically

public

Parameters
stringcolumn value

Definition at line 112 of file class.ilCSVWriter.php.

References $delimiter, $separator, and quote().

113  {
114  if (!$this->first_entry) {
115  $this->csv .= $this->separator;
116  }
117  $this->csv .= $this->delimiter;
118  $this->csv .= $this->quote($a_col);
119  $this->csv .= $this->delimiter;
120  $this->first_entry = false;
121  }
quote($a_str)
Quote Delimiter by doubling it This seems to be the standard way in Excel and Openoffice.
+ Here is the call graph for this function:

◆ addRow()

ilCSVWriter::addRow ( )

Add new line.

public

Definition at line 88 of file class.ilCSVWriter.php.

References $new_line.

89  {
90  $this->csv .= $this->new_line;
91  $this->first_entry = true;
92  }

◆ getCSVString()

ilCSVWriter::getCSVString ( )

Get CSV string.

public

Parameters

Definition at line 130 of file class.ilCSVWriter.php.

References $csv.

131  {
132  return $this->csv;
133  }

◆ quote()

ilCSVWriter::quote (   $a_str)
private

Quote Delimiter by doubling it This seems to be the standard way in Excel and Openoffice.

private

Parameters
stringfield value

Definition at line 143 of file class.ilCSVWriter.php.

Referenced by addColumn().

144  {
145  return str_replace($this->delimiter, $this->delimiter . $this->delimiter, ($this->doUTF8Decoding) ? utf8_decode($a_str) : $a_str);
146  }
+ Here is the caller graph for this function:

◆ setDelimiter()

ilCSVWriter::setDelimiter (   $a_del)

Set delimiter.

public

Parameters
stringfield delimiter

Definition at line 77 of file class.ilCSVWriter.php.

78  {
79  $this->delimiter = $a_del;
80  }

◆ setDoUTF8Decoding()

ilCSVWriter::setDoUTF8Decoding (   $doUTF8Decoding)

set to true if you want to utf8 decode for output.

Parameters
doUTF8Decodingboolean if set to true file is written using a utf8decode before writing values

Definition at line 100 of file class.ilCSVWriter.php.

References $doUTF8Decoding.

101  {
102  $this->doUTF8Decoding = $doUTF8Decoding ? true : false;
103  }

◆ setSeparator()

ilCSVWriter::setSeparator (   $a_sep)

Set Seperator.

public

Parameters
stringfield seperator

Definition at line 65 of file class.ilCSVWriter.php.

66  {
67  $this->separator = $a_sep;
68  }

Field Documentation

◆ $csv

ilCSVWriter::$csv = ''
private

Definition at line 40 of file class.ilCSVWriter.php.

Referenced by getCSVString().

◆ $delimiter

ilCSVWriter::$delimiter = '"'
private

Definition at line 42 of file class.ilCSVWriter.php.

Referenced by addColumn().

◆ $doUTF8Decoding

ilCSVWriter::$doUTF8Decoding = false
private

Definition at line 44 of file class.ilCSVWriter.php.

Referenced by setDoUTF8Decoding().

◆ $first_entry

ilCSVWriter::$first_entry = true
private

Definition at line 46 of file class.ilCSVWriter.php.

◆ $new_line

ilCSVWriter::$new_line = "\n"
private

Definition at line 43 of file class.ilCSVWriter.php.

Referenced by addRow().

◆ $separator

ilCSVWriter::$separator = ','
private

Definition at line 41 of file class.ilCSVWriter.php.

Referenced by addColumn().


The documentation for this class was generated from the following file: