Csv
in package
CSV class
Tags
Table of Contents
Properties
Methods
- __construct() : mixed
- Constructor
- __toString() : string
- Render CSV string data to string
- appendDataToFile() : void
- Append additional CSV data to a pre-existing file
- appendRowToFile() : void
- Append additional CSV row of data to a pre-existing file
- getData() : array<string|int, mixed>
- Get data
- getDataFromFile() : array<string|int, mixed>
- Load CSV file and get data
- getFieldHeaders() : string
- Get field headers
- getString() : string
- Get string
- isSerialized() : bool
- Check if data was serialized
- isUnserialized() : bool
- Check if string was unserialized
- isValid() : bool
- Determine if the string is valid CSV
- loadData() : Csv
- Load CSV data
- loadFile() : Csv
- Load CSV file
- loadString() : Csv
- Load CSV string
- outputBlankFileToHttp() : void
- Output CSV headers only in a blank file to HTTP
- outputDataToHttp() : void
- Write data to file
- outputTemplateToHttp() : void
- Write data to file
- outputToHttp() : void
- Output CSV string data to HTTP
- prepareHttp() : void
- Prepare output to HTTP
- processOptions() : array<string|int, mixed>
- Process CSV options
- serialize() : string
- Serialize the data to a CSV string
- serializeData() : string
- Convert the data into CSV format.
- serializeRow() : string
- Serialize single row of data
- setData() : Csv
- Set data
- setString() : Csv
- Set string
- unserialize() : mixed
- Unserialize the string to data
- unserializeString() : array<string|int, mixed>
- Parse the CSV string into a PHP array
- writeBlankFile() : void
- Output CSV headers only to a blank file
- writeDataToFile() : void
- Write data to file
- writeTemplateToFile() : void
- Write data to file
- writeToFile() : void
- Output CSV data to a file
Properties
$data
CSV data in PHP
protected
mixed
$data
= null
$string
CSV string
protected
string|null
$string
= null
Methods
__construct()
Constructor
public
__construct([mixed $data = null ]) : mixed
Instantiate the Csv object.
Parameters
- $data : mixed = null
__toString()
Render CSV string data to string
public
__toString() : string
Return values
stringappendDataToFile()
Append additional CSV data to a pre-existing file
public
static appendDataToFile(string $file, array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ][, bool $validate = true ]) : void
Parameters
- $file : string
- $data : array<string|int, mixed>
- $options : array<string|int, mixed> = []
- $validate : bool = true
Tags
appendRowToFile()
Append additional CSV row of data to a pre-existing file
public
static appendRowToFile(string $file, array<string|int, mixed> $row[, array<string|int, mixed> $options = [] ][, bool $validate = true ]) : void
Parameters
- $file : string
- $row : array<string|int, mixed>
- $options : array<string|int, mixed> = []
- $validate : bool = true
Tags
getData()
Get data
public
getData() : array<string|int, mixed>
Return values
array<string|int, mixed>getDataFromFile()
Load CSV file and get data
public
static getDataFromFile(string $file[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $file : string
- $options : array<string|int, mixed> = []
Return values
array<string|int, mixed>getFieldHeaders()
Get field headers
public
static getFieldHeaders(mixed $data[, string $delimiter = ',' ][, array<string|int, mixed> $exclude = [] ][, array<string|int, mixed> $include = [] ]) : string
Parameters
- $data : mixed
- $delimiter : string = ','
- $exclude : array<string|int, mixed> = []
- $include : array<string|int, mixed> = []
Return values
stringgetString()
Get string
public
getString() : string
Return values
stringisSerialized()
Check if data was serialized
public
isSerialized() : bool
Return values
boolisUnserialized()
Check if string was unserialized
public
isUnserialized() : bool
Return values
boolisValid()
Determine if the string is valid CSV
public
static isValid(string $string) : bool
Parameters
- $string : string
Return values
boolloadData()
Load CSV data
public
static loadData(array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : Csv
Parameters
- $data : array<string|int, mixed>
- $options : array<string|int, mixed> = []
Return values
CsvloadFile()
Load CSV file
public
static loadFile(string $file[, array<string|int, mixed> $options = [] ]) : Csv
Parameters
- $file : string
- $options : array<string|int, mixed> = []
Return values
CsvloadString()
Load CSV string
public
static loadString(string $string[, array<string|int, mixed> $options = [] ]) : Csv
Parameters
- $string : string
- $options : array<string|int, mixed> = []
Return values
CsvoutputBlankFileToHttp()
Output CSV headers only in a blank file to HTTP
public
outputBlankFileToHttp([string $filename = 'pop-data.csv' ][, bool $forceDownload = true ][, array<string|int, mixed> $headers = [] ][, string $delimiter = ',' ][, array<string|int, mixed> $exclude = [] ]) : void
Parameters
- $filename : string = 'pop-data.csv'
- $forceDownload : bool = true
- $headers : array<string|int, mixed> = []
- $delimiter : string = ','
- $exclude : array<string|int, mixed> = []
Tags
outputDataToHttp()
Write data to file
public
static outputDataToHttp(array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ][, string $filename = 'pop-data.csv' ][, bool $forceDownload = true ][, array<string|int, mixed> $headers = [] ]) : void
Parameters
- $data : array<string|int, mixed>
- $options : array<string|int, mixed> = []
- $filename : string = 'pop-data.csv'
- $forceDownload : bool = true
- $headers : array<string|int, mixed> = []
outputTemplateToHttp()
Write data to file
public
static outputTemplateToHttp(array<string|int, mixed> $data[, string $filename = 'pop-data-template.csv' ][, bool $forceDownload = true ][, array<string|int, mixed> $headers = [] ][, string $delimiter = ',' ][, array<string|int, mixed> $exclude = [] ]) : void
Parameters
- $data : array<string|int, mixed>
- $filename : string = 'pop-data-template.csv'
- $forceDownload : bool = true
- $headers : array<string|int, mixed> = []
- $delimiter : string = ','
- $exclude : array<string|int, mixed> = []
Tags
outputToHttp()
Output CSV string data to HTTP
public
outputToHttp([string $filename = 'pop-data.csv' ][, bool $forceDownload = true ][, array<string|int, mixed> $headers = [] ]) : void
Parameters
- $filename : string = 'pop-data.csv'
- $forceDownload : bool = true
- $headers : array<string|int, mixed> = []
prepareHttp()
Prepare output to HTTP
public
prepareHttp([string $filename = 'pop-data.csv' ][, bool $forceDownload = true ][, array<string|int, mixed> $headers = [] ]) : void
Parameters
- $filename : string = 'pop-data.csv'
- $forceDownload : bool = true
- $headers : array<string|int, mixed> = []
processOptions()
Process CSV options
public
static processOptions(array<string|int, mixed> $options) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed>
Return values
array<string|int, mixed>serialize()
Serialize the data to a CSV string
public
serialize([array<string|int, mixed> $options = [] ]) : string
Parameters
- $options : array<string|int, mixed> = []
Return values
stringserializeData()
Convert the data into CSV format.
public
static serializeData(mixed $data[, array<string|int, mixed> $options = [] ]) : string
Parameters
- $data : mixed
- $options : array<string|int, mixed> = []
Return values
stringserializeRow()
Serialize single row of data
public
static serializeRow(array<string|int, mixed> $value[, array<string|int, mixed> $exclude = [] ][, array<string|int, mixed> $include = [] ][, string $delimiter = ',' ][, string $enclosure = '"' ][, string $escape = '"' ][, bool $newline = true ][, int $limit = 0 ]) : string
Parameters
- $value : array<string|int, mixed>
- $exclude : array<string|int, mixed> = []
- $include : array<string|int, mixed> = []
- $delimiter : string = ','
- $enclosure : string = '"'
- $escape : string = '"'
- $newline : bool = true
- $limit : int = 0
Return values
stringsetData()
Set data
public
setData(array<string|int, mixed> $data) : Csv
Parameters
- $data : array<string|int, mixed>
Return values
CsvsetString()
Set string
public
setString(string $string) : Csv
Parameters
- $string : string
Return values
Csvunserialize()
Unserialize the string to data
public
unserialize([array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $options : array<string|int, mixed> = []
unserializeString()
Parse the CSV string into a PHP array
public
static unserializeString(string $string[, array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $string : string
- $options : array<string|int, mixed> = []
Return values
array<string|int, mixed>writeBlankFile()
Output CSV headers only to a blank file
public
writeBlankFile(string $to[, string $delimiter = ',' ][, array<string|int, mixed> $exclude = [] ][, array<string|int, mixed> $include = [] ]) : void
Parameters
- $to : string
- $delimiter : string = ','
- $exclude : array<string|int, mixed> = []
- $include : array<string|int, mixed> = []
Tags
writeDataToFile()
Write data to file
public
static writeDataToFile(array<string|int, mixed> $data, string $to[, array<string|int, mixed> $options = [] ]) : void
Parameters
- $data : array<string|int, mixed>
- $to : string
- $options : array<string|int, mixed> = []
writeTemplateToFile()
Write data to file
public
static writeTemplateToFile(array<string|int, mixed> $data, string $to[, string $delimiter = ',' ][, array<string|int, mixed> $exclude = [] ][, array<string|int, mixed> $include = [] ]) : void
Parameters
- $data : array<string|int, mixed>
- $to : string
- $delimiter : string = ','
- $exclude : array<string|int, mixed> = []
- $include : array<string|int, mixed> = []
Tags
writeToFile()
Output CSV data to a file
public
writeToFile(string $to) : void
Parameters
- $to : string