Csv
in package
CSV class
Tags
Table of Contents
- $data : mixed
- CSV data in PHP
- $string : string
- CSV string
- __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() : self
- Load CSV data
- loadFile() : self
- Load CSV file
- loadString() : self
- Load CSV string
- outputDataToHttp() : void
- Write data to file
- outputToHttp() : void
- Output CSV string data 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
- writeDataToFile() : 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
$string
= null
Methods
__construct()
Constructor
public
__construct([mixed $data = null ]) : mixed
Instantiate the Csv object.
Parameters
- $data : mixed = null
Return values
mixed —__toString()
Render CSV string data to string
public
__toString() : string
Return values
string —appendDataToFile()
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
Return values
void —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
Return values
void —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> $omit = [] ]) : string
Parameters
- $data : mixed
- $delimiter : string = ','
- $omit : array<string|int, mixed> = []
Return values
string —getString()
Get string
public
getString() : string
Return values
string —isSerialized()
Check if data was serialized
public
isSerialized() : bool
Return values
bool —isUnserialized()
Check if string was unserialized
public
isUnserialized() : bool
Return values
bool —isValid()
Determine if the string is valid CSV
public
static isValid(string $string) : bool
Parameters
- $string : string
Return values
bool —loadData()
Load CSV data
public
static loadData(array<string|int, mixed> $data[, array<string|int, mixed> $options = [] ]) : self
Parameters
- $data : array<string|int, mixed>
- $options : array<string|int, mixed> = []
Return values
self —loadFile()
Load CSV file
public
static loadFile(string $file[, array<string|int, mixed> $options = [] ]) : self
Parameters
- $file : string
- $options : array<string|int, mixed> = []
Return values
self —loadString()
Load CSV string
public
static loadString(string $string[, array<string|int, mixed> $options = [] ]) : self
Parameters
- $string : string
- $options : array<string|int, mixed> = []
Return values
self —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> = []
Return values
void —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> = []
Return values
void —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
string —serializeData()
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
string —serializeRow()
Serialize single row of data;
public
static serializeRow(array<string|int, mixed> $value[, array<string|int, mixed> $omit = [] ][, string $delimiter = ',' ][, string $enclosure = '"' ][, string $escape = '"' ][, bool $newline = true ], int $limit) : string
Parameters
- $value : array<string|int, mixed>
- $omit : array<string|int, mixed> = []
- $delimiter : string = ','
- $enclosure : string = '"'
- $escape : string = '"'
- $newline : bool = true
- $limit : int
Return values
string —setData()
Set data
public
setData(array<string|int, mixed> $data) : Csv
Parameters
- $data : array<string|int, mixed>
Return values
Csv —setString()
Set string
public
setString(string $string) : Csv
Parameters
- $string : string
Return values
Csv —unserialize()
Unserialize the string to data
public
unserialize([array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $options : array<string|int, mixed> = []
Return values
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> —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> = []
Return values
void —writeToFile()
Output CSV data to a file
public
writeToFile(string $to) : void
Parameters
- $to : string