
Martin Marecek - 2014-07-19 20:49:37
//-- CSV OUTPUT --
function output_csv($delimiter = ";", $enclosure = "\"", $escape = "\""){ $result = "";
//-- LOAD COLS --
list($cols) = $this->dimension();
//-- ROWS --
foreach ($this->rows() as $row){
//-- COLS --
$cols_array = array();
for ($i = 0; $i < $cols; $i++){
//-- ESCAPE --
if (strpos($row[$i], $enclosure) !== false || strpos($row[$i], $delimiter) !== false){ $row[$i] = $enclosure.str_replace($enclosure, $escape.$enclosure, $row[$i]).$enclosure; }
//-- ITEM --
$cols_array[] = $row[$i];
}
//-- RESULT --
$result .= $new_line.implode($delimiter, $cols_array); $new_line = "\n";
}
//-- RETURN --
return $result;
}
//--------------------------------------------------
//-- ARRAY OUTPUT --
function output_array(){ $result = array();
//-- LOAD COLS --
list($cols) = $this->dimension();
//-- ROWS --
foreach ($this->rows() as $row){
//-- COLS --
$cols_array = array();
for ($i = 0; $i < $cols; $i++){ $cols_array[] = $row[$i]; }
$result[] = $cols_array;
}
//-- RETURN --
return $result;
}