ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
class.ilCSVReader.php
Go to the documentation of this file.
1<?php
2/*
3 +-----------------------------------------------------------------------------+
4 | ILIAS open source |
5 +-----------------------------------------------------------------------------+
6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne |
7 | |
8 | This program is free software; you can redistribute it and/or |
9 | modify it under the terms of the GNU General Public License |
10 | as published by the Free Software Foundation; either version 2 |
11 | of the License, or (at your option) any later version. |
12 | |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
17 | |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21 +-----------------------------------------------------------------------------+
22*/
23
35{
36 private $ptr_file = null;
37 private $data = array();
38 private $separator = ';';
39 private $delimiter = '""';
40 private $length = 1024;
41
49 public function __construct()
50 {
51
52 }
53
54 /*
55 * Set Seperator
56 *
57 * @access public
58 * @param string field seperator
59 *
60 */
61 public function setSeparator($a_sep)
62 {
63 $this->separator = $a_sep;
64 }
65
73 public function setDelimiter($a_del)
74 {
75 $this->delimiter = $a_del;
76 }
77
85 public function setLength($a_length)
86 {
87 $this->length = $a_length;
88 }
89
90 public function open($file = "")
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 }
98
99 public function close()
100 {
101 // see open();
102 ini_set("auto_detect_line_endings", $this->line_ends);
103
104 return( @fclose($this->ptr_file) );
105 }
106
114 public function getDataArrayFromCSVFile()
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 }
130
137 private function unquote($a_str)
138 {
139 return str_replace($this->delimiter.$this->delimiter, $this->delimiter,$a_str);
140 }
141}
142?>
print $file
unquote($a_str)
@access private
setDelimiter($a_del)
Set delimiter.
__construct()
Constructor.
setSeparator($a_sep)
setLength($a_length)
Set length.
getDataArrayFromCSVFile()
Get data as array from csv file.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled