ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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  }

Member Function Documentation

◆ close()

ilCSVReader::close ( )

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

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

◆ getDataArrayFromCSVFile()

ilCSVReader::getDataArrayFromCSVFile ( )

Get data as array from csv file.

public

Returns
array $this->data Data of file

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

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

114  {
115  $row = 0;
116 
117  while (($line = fgetcsv($this->ptr_file, $this->length, $this->separator)) !== false) {
118  for ($col = 0; $col < count($line); $col++) {
119  $this->data[$row][$col] = $this->unquote($line[$col]);
120  }
121 
122  ++$row;
123  }
124 
125  return $this->data;
126  }
$row
unquote($a_str)
private
$this data['403_header']
+ Here is the call graph for this function:

◆ open()

ilCSVReader::open (   $file = "")

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

References ilUtil\stripSlashes().

90  {
91  // #16643
92  $this->line_ends = ini_get("auto_detect_line_endings");
93  ini_set("auto_detect_line_endings", true);
94 
95  return($this->ptr_file = @fopen(ilUtil::stripSlashes($file), "r"));
96  }
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 72 of file class.ilCSVReader.php.

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

◆ setLength()

ilCSVReader::setLength (   $a_length)

Set length.

public

Parameters
intlength

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

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

◆ setSeparator()

ilCSVReader::setSeparator (   $a_sep)

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

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

◆ unquote()

ilCSVReader::unquote (   $a_str)
private

private

Parameters
stringfield value

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

Referenced by getDataArrayFromCSVFile().

135  {
136  return str_replace($this->delimiter . $this->delimiter, $this->delimiter, $a_str);
137  }
+ 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: