parseCSV::unparse PHP Method

unparse() public method

Create CSV data from array
public unparse ( $data = [], $fields = [], $append = false, $is_php = false, $delimiter = null ) : CSV
return CSV data (text string)
    function unparse($data = [], $fields = [], $append = false, $is_php = false, $delimiter = null)
    {
        if (!is_array($data) || empty($data)) {
            $data =& $this->data;
        }
        if (!is_array($fields) || empty($fields)) {
            $fields =& $this->titles;
        }
        if ($delimiter === null) {
            $delimiter = $this->delimiter;
        }
        $string = $is_php ? "<?php header('Status: 403'); die(' '); ?>" . $this->linefeed : '';
        $entry = [];
        // create heading
        if ($this->heading && !$append) {
            foreach ($fields as $key => $value) {
                $entry[] = $this->_enclose_value($value);
            }
            $string .= implode($delimiter, $entry) . $this->linefeed;
            $entry = [];
        }
        // create data
        foreach ($data as $key => $row) {
            foreach ($row as $field => $value) {
                $entry[] = $this->_enclose_value($value);
            }
            $string .= implode($delimiter, $entry) . $this->linefeed;
            $entry = [];
        }
        return $string;
    }

Usage Example

Beispiel #1
0
               
            }
            /*if(cellProperties.readOnly) {
              td.style.opacity = 0.7;
            }*/

            if(!value || value === '') {
              td.style.background = '#EEE';
            }
            else {
              td.style.background = '';
            }
          }

          var data = <?php 
echo json_encode($csv->unparse($csv->data, $csv->titles, null, null, null, true));
?>
;

          var container = $("#example1");
          var hand = container.handsontable({
			data: data,
            startRows: data.length,  //<?php 
echo $csv->filelines('../out/test.csv');
?>
,
			startCols: <?php 
echo count($csv->titles);
?>
,
			rowHeaders: true, //turn on 1, 2, 3, ...
All Usage Examples Of parseCSV::unparse