ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f87
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 99 of file class.ilCSVReader.php.

100  {
101  // see open();
102  ini_set("auto_detect_line_endings", $this->line_ends);
103 
104  return( @fclose($this->ptr_file) );
105  }

◆ getDataArrayFromCSVFile()

ilCSVReader::getDataArrayFromCSVFile ( )

Get data as array from csv file.

public

Returns
array $this->data Data of file

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

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

115  {
116  $row = 0;
117 
118  while (($line = fgetcsv($this->ptr_file, $this->length, $this->separator)) !== FALSE)
119  {
120  for ($col = 0; $col < count($line); $col++)
121  {
122  $this->data[$row][$col] = $this->unquote($line[$col]);
123  }
124 
125  ++$row;
126  }
127 
128  return $this->data;
129  }
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  // #16643
93  $this->line_ends = ini_get("auto_detect_line_endings");
94  ini_set("auto_detect_line_endings", true);
95 
96  return( $this->ptr_file = @fopen(ilUtil::stripSlashes($file), "r") );
97  }
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 137 of file class.ilCSVReader.php.

Referenced by getDataArrayFromCSVFile().

138  {
139  return str_replace($this->delimiter.$this->delimiter, $this->delimiter,$a_str);
140  }
+ 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: