PHP Class parseCSV

Show file Open project: hillelcoren/invoice-ninja Class Usage Examples

Public Properties

Property Type Description
$auto_depth # number of rows to analyze when attempting to auto-detect delimiter
$auto_non_chars # characters to ignore when attempting to auto-detect delimiter
$auto_preferred # returns multiple possible delimiters (happens very rarely)
$conditions # basic SQL-like conditions for row matching
$convert_encoding # character encoding options
$data # two dimentional array of CSV data
$delimiter # delimiter (comma) and enclosure (double quote)
$enclosure
$fields # override field names
$file # current file
$file_data # loaded file contents
$heading # use first line/entry as field names
$input_encoding
$limit # limits the number of returned rows to specified amount
$linefeed # used by unparse(), save(), and output() functions
$offset # number of rows to ignore from beginning of data
$output_delimiter # only used by output() function
$output_encoding
$output_filename
$sort_by # sort entries by this field
$sort_reverse
$titles # array of field values in data parsed

Public Methods

Method Description
__construct ( $input = null, $offset = null, $limit = null, $conditions = null ) : nothing Constructor
_check_count ( $char, $array, $depth, $preferred ) : special Check if passed info might be delimiter - only used by find_delimiter()
_check_data ( $file = null ) : true Check file data
_enclose_value ( $value = null ) : Processed Enclose values if needed - only used by unparse()
_rfile ( $file = null ) : Data Read local file
_validate_offset ( $current_row ) : true Validates if the row is within the offset or not if sorting is disabled
_validate_row_condition ( $row, $condition ) : true Validate a row against a single condition
_validate_row_conditions ( $row = [], $conditions = null ) : true Validate a row against specified conditions
_wfile ( $file, $string = '', $mode = 'wb', $lock = 2 ) : true Write to local file
auto ( $file = null, $parse = true, $search_depth = null, $preferred = null, $enclosure = null ) : delimiter Auto-Detect Delimiter: Find delimiter by analyzing a specific number of rows to determine most probable delimiter character
encoding ( $input = null, $output = null ) : nothing Convert character encoding
load_data ( $input = null ) : true Load local file or string
output ( $output = true, $filename = null, $data = [], $fields = [], $delimiter = null ) : CSV Generate CSV based string for output
parse ( $input = null, $offset = null, $limit = null, $conditions = null ) : nothing Parse CSV file or string
parse_file ( $file = null ) : 2D Read file to string and call parse_string()
parse_string ( $data = null ) : 2D Parse CSV strings to arrays
save ( $file = null, $data = [], $append = false, $fields = [] ) : true Save changes, or new file and/or data
unparse ( $data = [], $fields = [], $append = false, $is_php = false, $delimiter = null ) : CSV Create CSV data from array

Method Details

__construct() public method

Constructor
public __construct ( $input = null, $offset = null, $limit = null, $conditions = null ) : nothing
return nothing

_check_count() public method

Check if passed info might be delimiter - only used by find_delimiter()
public _check_count ( $char, $array, $depth, $preferred ) : special
return special string used for delimiter selection, or false

_check_data() public method

Check file data
public _check_data ( $file = null ) : true
return true or false

_enclose_value() public method

Enclose values if needed - only used by unparse()
public _enclose_value ( $value = null ) : Processed
return Processed value

_rfile() public method

Read local file
public _rfile ( $file = null ) : Data
return Data from file, or false on failure

_validate_offset() public method

Validates if the row is within the offset or not if sorting is disabled
public _validate_offset ( $current_row ) : true
return true of false

_validate_row_condition() public method

Validate a row against a single condition
public _validate_row_condition ( $row, $condition ) : true
return true of false

_validate_row_conditions() public method

Validate a row against specified conditions
public _validate_row_conditions ( $row = [], $conditions = null ) : true
return true of false

_wfile() public method

Write to local file
public _wfile ( $file, $string = '', $mode = 'wb', $lock = 2 ) : true
return true or false

auto() public method

Auto-Detect Delimiter: Find delimiter by analyzing a specific number of rows to determine most probable delimiter character
public auto ( $file = null, $parse = true, $search_depth = null, $preferred = null, $enclosure = null ) : delimiter
return delimiter character

encoding() public method

Convert character encoding
public encoding ( $input = null, $output = null ) : nothing
return nothing

load_data() public method

Load local file or string
public load_data ( $input = null ) : true
return true or false

output() public method

Generate CSV based string for output
public output ( $output = true, $filename = null, $data = [], $fields = [], $delimiter = null ) : CSV
return CSV data using delimiter of choice, or default

parse() public method

Parse CSV file or string
public parse ( $input = null, $offset = null, $limit = null, $conditions = null ) : nothing
return nothing

parse_file() public method

Read file to string and call parse_string()
public parse_file ( $file = null ) : 2D
return 2D

parse_string() public method

Parse CSV strings to arrays
public parse_string ( $data = null ) : 2D
return 2D

save() public method

Save changes, or new file and/or data
public save ( $file = null, $data = [], $append = false, $fields = [] ) : true
return true or false

unparse() public method

Create CSV data from array
public unparse ( $data = [], $fields = [], $append = false, $is_php = false, $delimiter = null ) : CSV
return CSV data (text string)

Property Details

$auto_depth public property

# number of rows to analyze when attempting to auto-detect delimiter
public $auto_depth

$auto_non_chars public property

# characters to ignore when attempting to auto-detect delimiter
public $auto_non_chars

$auto_preferred public property

# returns multiple possible delimiters (happens very rarely)
public $auto_preferred

$conditions public property

# basic SQL-like conditions for row matching
public $conditions

$convert_encoding public property

# character encoding options
public $convert_encoding

$data public property

# two dimentional array of CSV data
public $data

$delimiter public property

# delimiter (comma) and enclosure (double quote)
public $delimiter

$enclosure public property

public $enclosure

$fields public property

# override field names
public $fields

$file public property

# current file
public $file

$file_data public property

# loaded file contents
public $file_data

$heading public property

# use first line/entry as field names
public $heading

$input_encoding public property

public $input_encoding

$limit public property

# limits the number of returned rows to specified amount
public $limit

$linefeed public property

# used by unparse(), save(), and output() functions
public $linefeed

$offset public property

# number of rows to ignore from beginning of data
public $offset

$output_delimiter public property

# only used by output() function
public $output_delimiter

$output_encoding public property

public $output_encoding

$output_filename public property

public $output_filename

$sort_by public property

# sort entries by this field
public $sort_by

$sort_reverse public property

public $sort_reverse

$titles public property

# array of field values in data parsed
public $titles