Go to the documentation of this file.00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00034 class ilCSVReader
00035 {
00036 private $ptr_file = null;
00037 private $data = array();
00038 private $separator = ';';
00039 private $delimiter = '""';
00040 private $length = 1024;
00041
00049 public function __construct()
00050 {
00051
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061 public function setSeparator($a_sep)
00062 {
00063 $this->separator = $a_sep;
00064 }
00065
00073 public function setDelimiter($a_del)
00074 {
00075 $this->delimiter = $a_del;
00076 }
00077
00085 public function setLength($a_length)
00086 {
00087 $this->length = $a_length;
00088 }
00089
00090 public function open($file = "")
00091 {
00092 return( $this->ptr_file = @fopen(ilUtil::stripSlashes($file), "r") );
00093 }
00094
00095 public function close()
00096 {
00097 return( @fclose($this->ptr_file) );
00098 }
00099
00107 public function getDataArrayFromCSVFile()
00108 {
00109 $row = 0;
00110
00111 while (($line = fgetcsv($this->ptr_file, $this->length, $this->separator)) !== FALSE)
00112 {
00113 for ($col = 0; $col < count($line); $col++)
00114 {
00115 $this->data[$row][$col] = $this->unquote($line[$col]);
00116 }
00117
00118 ++$row;
00119 }
00120
00121 return $this->data;
00122 }
00123
00130 private function unquote($a_str)
00131 {
00132 return str_replace($this->delimiter.$this->delimiter, $this->delimiter,$a_str);
00133 }
00134 }
00135 ?>