PHP Classes

Add output functions (CSV, ARRAY)

Recommend this page to a friend!

      SimpleXLSX  >  All threads  >  Add output functions (CSV, ARRAY)  >  (Un) Subscribe thread alerts  
Subject:Add output functions (CSV, ARRAY)
Summary:output functions CSV ARRAY
Messages:1
Author:Martin Marecek
Date:2014-07-19 20:49:37
 

  1. Add output functions (CSV, ARRAY)   Reply   Report abuse  
Picture of Martin Marecek 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;
}