ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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.

@access public

Parameters

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

56 {
57
58 }

Member Function Documentation

◆ addColumn()

ilCSVWriter::addColumn (   $a_col)

Add Column.

Will be quoted automatically

@access public

Parameters
stringcolumn value

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

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

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

+ Here is the call graph for this function:

◆ addRow()

ilCSVWriter::addRow ( )

Add new line.

@access public

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

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

References $new_line.

◆ getCSVString()

ilCSVWriter::getCSVString ( )

Get CSV string.

@access public

Parameters

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

133 {
134 return $this->csv;
135 }

References $csv.

◆ quote()

ilCSVWriter::quote (   $a_str)
private

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

@access private

Parameters
stringfield value

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

146 {
147 return str_replace($this->delimiter,$this->delimiter.$this->delimiter, ($this->doUTF8Decoding) ? utf8_decode( $a_str ) : $a_str);
148 }

Referenced by addColumn().

+ Here is the caller graph for this function:

◆ setDelimiter()

ilCSVWriter::setDelimiter (   $a_del)

Set delimiter.

@access public

Parameters
stringfield delimiter

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

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

◆ 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 101 of file class.ilCSVWriter.php.

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

References $doUTF8Decoding.

◆ setSeparator()

ilCSVWriter::setSeparator (   $a_sep)

Set Seperator.

@access public

Parameters
stringfield seperator

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

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

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: