include/parsecsv.lib.php
\parseCSV
Properties
$heading= 'true'
Configuration - set these options with $object->var_name = 'value';
true
Details- Type
- n/a
Methods
_check_count(
$char, $array, $depth, $preferred
)
:
\special
Check if passed info might be delimiter - only used by find_delimiter()
Name | Type | Description |
---|---|---|
$char | ||
$array | ||
$depth | ||
$preferred |
Type | Description |
---|---|
\special | string used for delimiter selection, or false |
_check_data(
\file $file
=
null
)
:
true
Check file data
Name | Type | Description |
---|---|---|
$file | \file | local filename |
Type | Description |
---|---|
true | or false |
_enclose_value(
\value $value
=
null
)
:
\Processed
Enclose values if needed - only used by unparse()
Name | Type | Description |
---|---|---|
$value | \value | string to process |
Type | Description |
---|---|
\Processed | value |
_rfile(
\file $file
=
null
)
:
\Data
Read local file
Name | Type | Description |
---|---|---|
$file | \file | local filename |
Type | Description |
---|---|
\Data | from file, or false on failure |
_validate_offset(
\current_row $current_row
)
:
true
Validates if the row is within the offset or not if sorting is disabled
Name | Type | Description |
---|---|---|
$current_row | \current_row | the current row number being processed |
Type | Description |
---|---|
true | of false |
_validate_row_condition(
\row $row, \condition $condition
)
:
true
Validate a row against a single condition
Name | Type | Description |
---|---|---|
$row | \row | array with values from a row |
$condition | \condition | specified condition that the row must match |
Type | Description |
---|---|
true | of false |
_validate_row_conditions(
\row $row
=
array(), \conditions $conditions
=
null
)
:
true
Validate a row against specified conditions
Name | Type | Description |
---|---|---|
$row | \row | array with values from a row |
$conditions | \conditions | specified conditions that the row must match |
Type | Description |
---|---|
true | of false |
_wfile(
\file $file, string $string
=
'', \mode $mode
=
'wb', \lock $lock
=
2
)
:
true
Write to local file
Name | Type | Description |
---|---|---|
$file | \file | local filename |
$string | string | data to write to file |
$mode | \mode | fopen() mode |
$lock | \lock | flock() mode |
Type | Description |
---|---|
true | or false |
auto(
\file $file
=
null, \parse $parse
=
true, \search_depth $search_depth
=
null, \preferred $preferred
=
null, \enclosure $enclosure
=
null
)
:
\delimiter
Auto-Detect Delimiter: Find delimiter by analyzing a specific number of rows to determine most probable delimiter character
Name | Type | Description |
---|---|---|
$file | \file | local CSV file |
$parse | \parse | true/false parse file directly |
$search_depth | \search_depth | number of rows to analyze |
$preferred | \preferred | preferred delimiter characters |
$enclosure | \enclosure | enclosure character, default is double quote ("). |
Type | Description |
---|---|
\delimiter | character |
encoding(
\input $input
=
null, \output $output
=
null
)
:
\nothing
Convert character encoding
Name | Type | Description |
---|---|---|
$input | \input | input character encoding, uses default if left blank |
$output | \output | output character encoding, uses default if left blank |
Type | Description |
---|---|
\nothing |
load_data(
\input $input
=
null
)
:
true
Load local file or string
Name | Type | Description |
---|---|---|
$input | \input | local CSV file |
Type | Description |
---|---|
true | or false |
output(
\filename $filename
=
null, \data $data
=
array(), \fields $fields
=
array(), \delimiter $delimiter
=
null
)
:
\CSV
Generate CSV based string for output
Name | Type | Description |
---|---|---|
$filename | \filename | if specified, headers and data will be output directly to browser as a downloable file |
$data | \data | 2D array with data |
$fields | \fields | field names |
$delimiter | \delimiter | delimiter used to separate data |
Type | Description |
---|---|
\CSV | data using delimiter of choice, or default |
parse(
\input $input
=
null, $offset
=
null, $limit
=
null, $conditions
=
null
)
:
\nothing
Parse CSV file or string
Name | Type | Description |
---|---|---|
$input | \input | CSV file or string |
$offset | ||
$limit | ||
$conditions |
Type | Description |
---|---|
\nothing |
parseCSV(
\input $input
=
null, $offset
=
null, $limit
=
null, $conditions
=
null
)
:
\nothing
Constructor
Name | Type | Description |
---|---|---|
$input | \input | CSV file or string |
$offset | ||
$limit | ||
$conditions |
Type | Description |
---|---|
\nothing |
parse_file(
\file $file
=
null
)
:
\2D
Read file to string and call parse_string()
Name | Type | Description |
---|---|---|
$file | \file | local CSV file |
Type | Description |
---|---|
\2D | array with CSV data, or false on failure |
parse_string(
\data $data
=
null
)
:
\2D
Parse CSV strings to arrays
Name | Type | Description |
---|---|---|
$data | \data | CSV string |
Type | Description |
---|---|
\2D | array with CSV data, or false on failure |
save(
\file $file
=
null, \data $data
=
array(), \append $append
=
false, \fields $fields
=
array()
)
:
true
Save changes, or new file and/or data
Name | Type | Description |
---|---|---|
$file | \file | file to save to |
$data | \data | 2D array with data |
$append | \append | append current data to end of target CSV if exists |
$fields | \fields | field names |
Type | Description |
---|---|
true | or false |
unparse(
\data $data
=
array(), \fields $fields
=
array(), \append $append
=
false, \is_php $is_php
=
false, \delimiter $delimiter
=
null
)
:
\CSV
Create CSV data from array
Name | Type | Description |
---|---|---|
$data | \data | 2D array with data |
$fields | \fields | field names |
$append | \append | if true, field names will not be output |
$is_php | \is_php | if a php die() call should be put on the first line of the file, this is later ignored when read. |
$delimiter | \delimiter | field delimiter to use |
Type | Description |
---|---|
\CSV | data (text string) |