parseCSV::output PHP Method

output() public method

Generate CSV based string for output
public output ( $output = true, $filename = null, $data = [], $fields = [], $delimiter = null ) : CSV
return CSV data using delimiter of choice, or default
    function output($output = true, $filename = null, $data = [], $fields = [], $delimiter = null)
    {
        if (empty($filename)) {
            $filename = $this->output_filename;
        }
        if ($delimiter === null) {
            $delimiter = $this->output_delimiter;
        }
        $data = $this->unparse($data, $fields, null, null, $delimiter);
        if ($output) {
            header('Content-type: application/csv');
            header('Content-Disposition: inline; filename="' . $filename . '"');
            echo $data;
        }
        return $data;
    }

Usage Example

 /**
  * Renders the CSV.
  *
  * @return void
  */
 public function process()
 {
     $params = $this->gp;
     $exportParams = Tx_Formhandler_StaticFuncs::getSingle($this->settings, 'exportParams');
     if (!is_array($exportParams)) {
         $exportParams = t3lib_div::trimExplode(',', $exportParams);
     }
     //build data
     foreach ($params as $key => &$value) {
         if (is_array($value)) {
             $value = implode(',', $value);
         }
         if (count($exportParams) > 0 && !in_array($key, $exportParams)) {
             unset($params[$key]);
         }
         $value = str_replace('"', '""', $value);
     }
     // create new parseCSV object.
     $csv = new parseCSV();
     $csv->output('formhandler.csv', $data, $params);
     die;
 }
All Usage Examples Of parseCSV::output