ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
ilCSVReader Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Collaboration diagram for ilCSVReader:

Public Member Functions

 setSeparator (string $a_sep)
 
 setDelimiter (string $a_del)
 
 setLength (int $a_length)
 
 open (string $path_to_file)
 
 close ()
 
 getCsvAsArray ()
 

Private Member Functions

 parse ()
 
 unquote (string $a_str)
 

Private Attributes

 $file_resource
 
string $line_ends
 
array $data = []
 
string $separator = ';'
 
string $delimiter = '""'
 
int $length = 1024
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

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

Member Function Documentation

◆ close()

ilCSVReader::close ( )

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

70  : bool
71  {
72  return fclose($this->file_resource);
73  }

◆ getCsvAsArray()

ilCSVReader::getCsvAsArray ( )

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

References $data, and parse().

75  : array
76  {
77  $this->parse();
78 
79  return $this->data;
80  }
+ Here is the call graph for this function:

◆ open()

ilCSVReader::open ( string  $path_to_file)

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

References ilUtil\stripSlashes().

60  : bool
61  {
62  $this->file_resource = fopen(ilUtil::stripSlashes($path_to_file), "r");
63 
64  if (!is_resource($this->file_resource)) {
65  throw new RuntimeException('sould not open stream to ' . $path_to_file);
66  }
67  return true;
68  }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")
+ Here is the call graph for this function:

◆ parse()

ilCSVReader::parse ( )
private

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

References unquote().

Referenced by getCsvAsArray().

31  : void
32  {
33  $row = 0;
34 
35  while (($line = fgetcsv($this->file_resource, $this->length, $this->separator)) !== false) {
36  $line_count = count($line);
37  for ($col = 0; $col < $line_count; $col++) {
38  $this->data[$row][$col] = $this->unquote($line[$col]);
39  }
40 
41  ++$row;
42  }
43  }
unquote(string $a_str)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setDelimiter()

ilCSVReader::setDelimiter ( string  $a_del)

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

50  : void
51  {
52  $this->delimiter = $a_del;
53  }

◆ setLength()

ilCSVReader::setLength ( int  $a_length)

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

55  : void
56  {
57  $this->length = $a_length;
58  }

◆ setSeparator()

ilCSVReader::setSeparator ( string  $a_sep)

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

45  : void
46  {
47  $this->separator = $a_sep;
48  }

◆ unquote()

ilCSVReader::unquote ( string  $a_str)
private

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

Referenced by parse().

82  : string
83  {
84  return str_replace($this->delimiter . $this->delimiter, $this->delimiter, $a_str);
85  }
+ Here is the caller graph for this function:

Field Documentation

◆ $data

array ilCSVReader::$data = []
private

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

Referenced by getCsvAsArray().

◆ $delimiter

string ilCSVReader::$delimiter = '""'
private

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

◆ $file_resource

ilCSVReader::$file_resource
private

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

◆ $length

int ilCSVReader::$length = 1024
private

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

◆ $line_ends

string ilCSVReader::$line_ends
private

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

◆ $separator

string ilCSVReader::$separator = ';'
private

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


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