ILIAS  release_4-4 Revision
ilCSVReader Class Reference
+ Collaboration diagram for ilCSVReader:

Public Member Functions

 __construct ()
 Constructor. More...
 
 setSeparator ($a_sep)
 
 setDelimiter ($a_del)
 Set delimiter. More...
 
 setLength ($a_length)
 Set length. More...
 
 open ($file="")
 
 close ()
 
 getDataArrayFromCSVFile ()
 Get data as array from csv file. More...
 

Private Member Functions

 unquote ($a_str)
 private More...
 

Private Attributes

 $ptr_file = null
 
 $data = array()
 
 $separator = ';'
 
 $delimiter = '""'
 
 $length = 1024
 

Detailed Description

Author
Michael Jansen mjans.nosp@m.en@d.nosp@m.ataba.nosp@m.y.de
Version
$Id$

Definition at line 34 of file class.ilCSVReader.php.

Constructor & Destructor Documentation

◆ __construct()

ilCSVReader::__construct ( )

Constructor.

public

Parameters

Definition at line 49 of file class.ilCSVReader.php.

50  {
51 
52  }

Member Function Documentation

◆ close()

ilCSVReader::close ( )

Definition at line 95 of file class.ilCSVReader.php.

96  {
97  return( @fclose($this->ptr_file) );
98  }

◆ getDataArrayFromCSVFile()

ilCSVReader::getDataArrayFromCSVFile ( )

Get data as array from csv file.

public

Returns
array $this->data Data of file

Definition at line 107 of file class.ilCSVReader.php.

References $data, $row, and unquote().

108  {
109  $row = 0;
110 
111  while (($line = fgetcsv($this->ptr_file, $this->length, $this->separator)) !== FALSE)
112  {
113  for ($col = 0; $col < count($line); $col++)
114  {
115  $this->data[$row][$col] = $this->unquote($line[$col]);
116  }
117 
118  ++$row;
119  }
120 
121  return $this->data;
122  }
unquote($a_str)
private
+ Here is the call graph for this function:

◆ open()

ilCSVReader::open (   $file = "")

Definition at line 90 of file class.ilCSVReader.php.

References $file, and ilUtil\stripSlashes().

91  {
92  return( $this->ptr_file = @fopen(ilUtil::stripSlashes($file), "r") );
93  }
print $file
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
+ Here is the call graph for this function:

◆ setDelimiter()

ilCSVReader::setDelimiter (   $a_del)

Set delimiter.

public

Parameters
stringfield delimiter

Definition at line 73 of file class.ilCSVReader.php.

74  {
75  $this->delimiter = $a_del;
76  }

◆ setLength()

ilCSVReader::setLength (   $a_length)

Set length.

public

Parameters
intlength

Definition at line 85 of file class.ilCSVReader.php.

86  {
87  $this->length = $a_length;
88  }

◆ setSeparator()

ilCSVReader::setSeparator (   $a_sep)

Definition at line 61 of file class.ilCSVReader.php.

62  {
63  $this->separator = $a_sep;
64  }

◆ unquote()

ilCSVReader::unquote (   $a_str)
private

private

Parameters
stringfield value

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

Referenced by getDataArrayFromCSVFile().

131  {
132  return str_replace($this->delimiter.$this->delimiter, $this->delimiter,$a_str);
133  }
+ Here is the caller graph for this function:

Field Documentation

◆ $data

ilCSVReader::$data = array()
private

Definition at line 37 of file class.ilCSVReader.php.

Referenced by getDataArrayFromCSVFile().

◆ $delimiter

ilCSVReader::$delimiter = '""'
private

Definition at line 39 of file class.ilCSVReader.php.

◆ $length

ilCSVReader::$length = 1024
private

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

◆ $ptr_file

ilCSVReader::$ptr_file = null
private

Definition at line 36 of file class.ilCSVReader.php.

◆ $separator

ilCSVReader::$separator = ';'
private

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


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