ILIAS  trunk Revision v11.0_alpha-1744-gb0451eebef4
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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 = '""'
 
string $escape = '\\'
 
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 71 of file class.ilCSVReader.php.

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

◆ getCsvAsArray()

ilCSVReader::getCsvAsArray ( )

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

References $data, and parse().

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

◆ open()

ilCSVReader::open ( string  $path_to_file)

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

References ilUtil\stripSlashes().

61  : bool
62  {
63  $this->file_resource = fopen(ilUtil::stripSlashes($path_to_file), "r");
64 
65  if (!is_resource($this->file_resource)) {
66  throw new RuntimeException('sould not open stream to ' . $path_to_file);
67  }
68  return true;
69  }
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 32 of file class.ilCSVReader.php.

References unquote().

Referenced by getCsvAsArray().

32  : void
33  {
34  $row = 0;
35 
36  while (($line = fgetcsv($this->file_resource, $this->length, $this->separator, $this->escape)) !== false) {
37  $line_count = count($line);
38  for ($col = 0; $col < $line_count; $col++) {
39  $this->data[$row][$col] = $this->unquote($line[$col]);
40  }
41 
42  ++$row;
43  }
44  }
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 51 of file class.ilCSVReader.php.

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

◆ setLength()

ilCSVReader::setLength ( int  $a_length)

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

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

◆ setSeparator()

ilCSVReader::setSeparator ( string  $a_sep)

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

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

◆ unquote()

ilCSVReader::unquote ( string  $a_str)
private

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

Referenced by parse().

83  : string
84  {
85  return str_replace($this->delimiter . $this->delimiter, $this->delimiter, $a_str);
86  }
+ 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.

◆ $escape

string ilCSVReader::$escape = '\\'
private

Definition at line 29 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 30 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: