Create a CSV file.
Takes arrays and turns them into CSV files.
| package | dstruct_presentation |
|---|---|
| author | David |
| todo | Accept recordset objects like DataTable? |
__construct(array $dataset) : string
Accepts multi-dimensional array suitable for addRows() and will return a csv output. Quick way of generating a csv, but not suitable if you want to change default field enclosure character, add headers etc.
array
stringCSV formatted string.addHeaders($headers)
addRow(array $arraydata)
The array will be added as a row to the end of the current data. Method does not check that the array has the correct number of items. This is expected behaviour.
arrayFlat array of data.
\DStructGeneralException |
|---|
addRows(array $data)
Expects a multi-dimensional array of data to output as a csv.
arrayMulti-dimensional array of data.
\DStructGeneralException |
|---|
clear()
Removes all data, counters and header info.
getHeaderCount() : integer
integersetEnclosedBy(string $by)
Default is nothing - fields will not be enclosed. Common setting would be double quotes. Must be set before any data or headers are added.
string
\DStructGeneralException |
|---|
setEscapeCharacter(string $char)
Default is \ (backslash). Must be set before any data or headers are added.
string
\DStructGeneralException |
|---|
setLineEnding(string $ending)
Default is windows style \r\n. You must set the string using double quotes! e.g.
$csvout->setLineEnding("\n"); // works!
$csvout->setLineEnding('\n'); // doesn't work!
string
\DStructGeneralException |
|---|
setSeparator(string $sep)
Default is a comma. Must be set before any headers or data.
string
\DStructGeneralException |
|---|
write(string $name, string $dest) : string
Can either stream to browser as csv, as a download, output a string for use in the script, or save as a local file. Note that the browser and download options can only be used if their has been no output from the script yet as they send headers.
stringIf streaming, downloading or saving can set name. Will default to export.csv if not given.
stringOutput destination. See notes and class constants.
\DStructGeneralException |
|---|
stringaddElement(string $element)
string
endLine()
$buffer : string
$enclosedby : string
$escape : string
$headercount : integer
$line : string
$separator : string
EXPORT_BROWSER : string
EXPORT_DOWNLOAD : string
EXPORT_FILE : string
EXPORT_STRING : string