Documentation

Csv
in package

CSV class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)

license

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

version
4.0.0

Table of Contents

Properties

$data  : mixed
CSV data in PHP
$string  : string|null
CSV string

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

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

loadFile()

Load CSV file

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

loadString()

Load CSV string

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

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
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> $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> $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
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> = []

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

writeToFile()

Output CSV data to a file

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

        
On this page

Search results