ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 * Set Seperator
55 *
56 * @access public
57 * @param string field seperator
58 *
59 */
60 public function setSeparator($a_sep)
61 {
62 $this->separator = $a_sep;
63 }
64
72 public function setDelimiter($a_del)
73 {
74 $this->delimiter = $a_del;
75 }
76
84 public function setLength($a_length)
85 {
86 $this->length = $a_length;
87 }
88
89 public function open($file = "")
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 }
97
98 public function close()
99 {
100 // see open();
101 ini_set("auto_detect_line_endings", $this->line_ends);
102
103 return(@fclose($this->ptr_file));
104 }
105
113 public function getDataArrayFromCSVFile()
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 }
127
134 private function unquote($a_str)
135 {
136 return str_replace($this->delimiter . $this->delimiter, $this->delimiter, $a_str);
137 }
138}
An exception for terminatinating execution or to throw for unit testing.
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
if(!file_exists("$old.txt")) if( $old===$new) if(file_exists("$new.txt")) $file
$this data['403_header']