Documentation

Csv
in package

CSV class

Tags
category

Pop

author

Nick Sagona, III dev@noladev.com

copyright

Copyright (c) 2009-2025 NOLA Interactive, LLC.

license

https://www.popphp.org/license New BSD License

version
4.2.0

Table of Contents

Properties

$data  : mixed
CSV data in PHP
$options  : array<string|int, mixed>
CSV options
$string  : string|null
CSV string

Methods

__construct()  : mixed
Constructor
__toString()  : string
Render CSV string data to string
appendData()  : self
Append additional CSV data to a pre-existing file
appendDataToFile()  : void
Append additional CSV data to a pre-existing file
appendRow()  : self
Append additional CSV row of 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
Output data to HTTP
outputTemplateToHttp()  : void
Output template to HTTP
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
setOptions()  : self
Serialize the data to a CSV string
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 template to file
writeToFile()  : void
Output CSV data to a file

Properties

$data

CSV data in PHP

protected mixed $data = null

$options

CSV options

protected array<string|int, mixed> $options = ['exclude' => [], 'include' => [], 'delimiter' => ',', 'enclosure' => '"', 'escape' => '"', 'fields' => true, 'newline' => true, 'limit' => 0, 'map' => [], 'columns' => []]

$string

CSV string

protected string|null $string = null

Methods

__construct()

Constructor

public __construct([mixed $data = null ][, array<string|int, mixed>|null $options = null ]) : mixed

Instantiate the Csv object.

Parameters
$data : mixed = null
$options : array<string|int, mixed>|null = null

__toString()

Render CSV string data to string

public __toString() : string
Return values
string

appendData()

Append additional CSV data to a pre-existing file

public appendData(string $file, array<string|int, mixed> $data[, bool $validate = true ]) : self
Parameters
$file : string
$data : array<string|int, mixed>
$validate : bool = true
Return values
self

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
Tags
throws
Exception

appendRow()

Append additional CSV row of data to a pre-existing file

public appendRow(string $file, array<string|int, mixed> $row[, bool $validate = true ]) : self
Parameters
$file : string
$row : array<string|int, mixed>
$validate : bool = true
Return values
self

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
throws
Exception

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>|null $options = null ]) : array<string|int, mixed>
Parameters
$file : string
$options : array<string|int, mixed>|null = null
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
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>|null $options = null ]) : Csv
Parameters
$data : array<string|int, mixed>
$options : array<string|int, mixed>|null = null
Return values
Csv

loadFile()

Load CSV file

public static loadFile(string $file[, array<string|int, mixed>|null $options = null ]) : Csv
Parameters
$file : string
$options : array<string|int, mixed>|null = null
Return values
Csv

loadString()

Load CSV string

public static loadString(string $string[, array<string|int, mixed>|null $options = null ]) : Csv
Parameters
$string : string
$options : array<string|int, mixed>|null = null
Return values
Csv

outputBlankFileToHttp()

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 = [] ][, array<string|int, mixed> $include = [] ]) : void
Parameters
$filename : string = 'pop-data.csv'
$forceDownload : bool = true
$headers : array<string|int, mixed> = []
$delimiter : string = ','
$exclude : array<string|int, mixed> = []
$include : array<string|int, mixed> = []
Tags
throws
Exception

outputDataToHttp()

Output data to HTTP

public static outputDataToHttp(array<string|int, mixed> $data[, array<string|int, mixed>|null $options = null ][, 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>|null = null
$filename : string = 'pop-data.csv'
$forceDownload : bool = true
$headers : array<string|int, mixed> = []

outputTemplateToHttp()

Output template to HTTP

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 = [] ][, array<string|int, mixed> $include = [] ]) : 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> = []
$include : array<string|int, mixed> = []
Tags
throws
Exception

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>|null $options = null ]) : string
Parameters
$options : array<string|int, mixed>|null = null
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> $exclude = [] ][, array<string|int, mixed> $include = [] ][, string $delimiter = ',' ][, string $enclosure = '"' ][, string $escape = '"' ][, bool $newline = true ][, int $limit = 0 ][, array<string|int, mixed> $map = [] ][, array<string|int, mixed> $columns = [] ]) : 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
$map : array<string|int, mixed> = []
$columns : array<string|int, mixed> = []
Return values
string

setData()

Set data

public setData(array<string|int, mixed> $data) : Csv
Parameters
$data : array<string|int, mixed>
Return values
Csv

setOptions()

Serialize the data to a CSV string

public setOptions(array<string|int, mixed> $options) : self
Parameters
$options : array<string|int, mixed>
Return values
self

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>|null $options = null ]) : mixed
Parameters
$options : array<string|int, mixed>|null = null

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
throws
Exception

writeDataToFile()

Write data to file

public static writeDataToFile(array<string|int, mixed> $data, string $to[, array<string|int, mixed>|null $options = null ]) : void
Parameters
$data : array<string|int, mixed>
$to : string
$options : array<string|int, mixed>|null = null

writeTemplateToFile()

Write template 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
throws
Exception

writeToFile()

Output CSV data to a file

public writeToFile(string $to) : void
Parameters
$to : string

        
On this page

Search results