Public Member Functions | Private Member Functions | Private Attributes

ilCSVWriter Class Reference
[Services/Utilities]

Helper class to generate CSV files. More...

Public Member Functions

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

Private Member Functions

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

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 <smeyer@databay.de>
Version:
$Id$

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


Constructor & Destructor Documentation

ilCSVWriter::__construct (  ) 

Constructor.

public

Parameters:
 

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

        {
                
        }


Member Function Documentation

ilCSVWriter::addColumn ( a_col  ) 

Add Column.

Will be quoted automatically

public

Parameters:
string column value

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

References quote().

        {
                if(!$this->first_entry)
                {
                        $this->csv .= $this->separator;
                }
                $this->csv .= $this->delimiter;
                $this->csv .= $this->quote($a_col);
                $this->csv .= $this->delimiter;
                $this->first_entry = false;
        }

Here is the call graph for this function:

ilCSVWriter::addRow (  ) 

Add new line.

public

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

        {
                $this->csv .= $this->new_line;
                $this->first_entry = true;
        }

ilCSVWriter::getCSVString (  ) 

Get CSV string.

public

Parameters:
 

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

        {
                return $this->csv;
        }

ilCSVWriter::quote ( a_str  )  [private]

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

private

Parameters:
string field value

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

Referenced by addColumn().

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

Here is the caller graph for this function:

ilCSVWriter::setDelimiter ( a_del  ) 

Set delimiter.

public

Parameters:
string field delimiter

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

        {
                $this->delimiter = $a_del;
        }

ilCSVWriter::setDoUTF8Decoding ( doUTF8Decoding  ) 

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

Parameters:
doUTF8Decoding boolean if set to true file is written using a utf8decode before writing values

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

References $doUTF8Decoding.

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

ilCSVWriter::setSeparator ( a_sep  ) 

Set Seperator.

public

Parameters:
string field seperator

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

        {
                $this->separator = $a_sep;
        }


Field Documentation

ilCSVWriter::$csv = '' [private]

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

ilCSVWriter::$delimiter = '"' [private]

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

ilCSVWriter::$doUTF8Decoding = false [private]

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

Referenced by setDoUTF8Decoding().

ilCSVWriter::$first_entry = true [private]

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

ilCSVWriter::$new_line = "\n" [private]

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

ilCSVWriter::$separator = ',' [private]

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


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