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
string
CSV 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.
array
Flat array of data.
\DStructGeneralException |
---|
addRows(array $data)
Expects a multi-dimensional array of data to output as a csv.
array
Multi-dimensional array of data.
\DStructGeneralException |
---|
clear()
Removes all data, counters and header info.
getHeaderCount() : integer
integer
setEnclosedBy(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.
string
If streaming, downloading or saving can set name. Will default to export.csv if not given.
string
Output destination. See notes and class constants.
\DStructGeneralException |
---|
string
addElement(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