ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
ilCSVReader Class Reference
+ 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 ()
 

Data Fields

const AUTO_DETECT_LINE_ENDINGS = "auto_detect_line_endings"
 

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

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

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

Member Function Documentation

◆ close()

ilCSVReader::close ( )

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

76  : bool
77  {
78  ini_set(self::AUTO_DETECT_LINE_ENDINGS, $this->line_ends);
79 
80  return fclose($this->file_resource);
81  }

◆ getCsvAsArray()

ilCSVReader::getCsvAsArray ( )

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

References $data, and parse().

83  : array
84  {
85  $this->parse();
86 
87  return $this->data;
88  }
+ Here is the call graph for this function:

◆ open()

ilCSVReader::open ( string  $path_to_file)

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

References ilUtil\stripSlashes().

63  : bool
64  {
65  $this->line_ends = ini_get(self::AUTO_DETECT_LINE_ENDINGS);
66  ini_set(self::AUTO_DETECT_LINE_ENDINGS, true);
67 
68  $this->file_resource = fopen(ilUtil::stripSlashes($path_to_file), "r");
69 
70  if (!is_resource($this->file_resource)) {
71  throw new RuntimeException('sould not open stream to ' . $path_to_file);
72  }
73  return true;
74  }
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 34 of file class.ilCSVReader.php.

References unquote().

Referenced by getCsvAsArray().

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

53  : void
54  {
55  $this->delimiter = $a_del;
56  }

◆ setLength()

ilCSVReader::setLength ( int  $a_length)

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

58  : void
59  {
60  $this->length = $a_length;
61  }

◆ setSeparator()

ilCSVReader::setSeparator ( string  $a_sep)

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

48  : void
49  {
50  $this->separator = $a_sep;
51  }

◆ unquote()

ilCSVReader::unquote ( string  $a_str)
private

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

Referenced by parse().

90  : string
91  {
92  return str_replace($this->delimiter . $this->delimiter, $this->delimiter, $a_str);
93  }
+ Here is the caller graph for this function:

Field Documentation

◆ $data

array ilCSVReader::$data = []
private

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

Referenced by getCsvAsArray().

◆ $delimiter

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

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

◆ $file_resource

ilCSVReader::$file_resource
private

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

◆ $length

int ilCSVReader::$length = 1024
private

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

◆ $line_ends

string ilCSVReader::$line_ends
private

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

◆ $separator

string ilCSVReader::$separator = ';'
private

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

◆ AUTO_DETECT_LINE_ENDINGS

const ilCSVReader::AUTO_DETECT_LINE_ENDINGS = "auto_detect_line_endings"

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


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