File
[ class tree: File ] [ index: File ] [ all elements ]

Class: File_CSV

Source Location: /File_CSV-1.0.0/File/CSV.php

Class Overview


File class for handling CSV files (Comma Separated Values), a common format for exchanging data.


Author(s):

Methods


Inherited Variables

Inherited Methods


Class Details

[line 77]
File class for handling CSV files (Comma Separated Values), a common format for exchanging data.

TODO:

  • Usage example and Doc
  • Use getPointer() in discoverFormat
  • Add a line counter for being able to output better error reports
  • Store the last error in GLOBALS and add File_CSV::getLastError()
Wish:
  • Other methods like readAll(), writeAll(), numFields(), numRows()
  • Try to detect if a CSV has header or not in discoverFormat() (not possible with CSV)
Known Bugs: (they has been analyzed but for the moment the impact in the speed for properly handle this uncommon cases is too high and won't be supported)
  • A field which is composed only by a single quoted separator (ie -> ;";";) is not handled properly
  • When there is exactly one field minus than the expected number and there is a field with a separator inside, the parser will throw the "wrong count" error
Info about CSV and links to other sources http://rfc.net/rfc4180.html



[ Top ]


Method Detail

discoverFormat   [line 612]

mixed discoverFormat( string $file, [array $extraSeps = array()])

Discover the format of a CSV file (the number of fields, the separator and if it quote string fields)
  • Return: Assoc array or false

Parameters:

string   $file   —  the CSV file name
array   $extraSeps   —  extra separators that should be checked for.

[ Top ]

getPointer   [line 157]

mixed getPointer( string $file, array &$conf, [string $mode = FILE_MODE_READ], [boolean $reset = false])

Return or create the file descriptor associated with a file
  • Return: A file resource or false

Parameters:

string   $file   —  The name of the file
array   &$conf   —  The configuration
string   $mode   —  The open node (ex: FILE_MODE_READ or FILE_MODE_WRITE)
boolean   $reset   —  if passed as true and resource for the file exists than the file pointer will be moved to the beginning

[ Top ]

raiseError   [line 87]

bool raiseError( string $error)

This raiseError method works in a different way. It will always return false (an error occurred) but it will call PEAR::raiseError() before it. If no default PEAR global handler is set, will trigger an error.
  • Return: always false

Parameters:

string   $error   —  The error message

[ Top ]

read   [line 417]

mixed read( string $file, array &$conf)

Reads a "row" from a CSV file and return it as an array
  • Return: Array or false

Parameters:

string   $file   —  The CSV file
array   &$conf   —  The configuration of the dest CSV

[ Top ]

readQuoted   [line 247]

mixed readQuoted( string $file, array &$conf)

Reads a row of data as an array from a CSV file. It's able to read memo fields with multiline data.
  • Return: Array with the data read or false on error/no more data

Parameters:

string   $file   —  The filename where to write the data
array   &$conf   —  The configuration of the dest CSV

[ Top ]

resetPointer   [line 736]

boolean resetPointer( string $file, array &$conf, string $mode)

Front to call getPointer and moving the resource to the beginning of the file Reset it if you like.
  • Return: true on success false on failure

Parameters:

string   $file   —  The name of the file
array   &$conf   —  The configuration
string   $mode   —  The open node (ex: FILE_MODE_READ or FILE_MODE_WRITE)

[ Top ]

unquote   [line 191]

string unquote( array|string $data, string $quote)

Unquote data
  • Return: the unquoted data

Parameters:

array|string   $data   —  The data to unquote
string   $quote   —  The quote char

[ Top ]

write   [line 546]

bool write( string $file, array $fields, array &$conf)

Writes a struc (array) in a file as CSV
  • Return: True on success false otherwise

Parameters:

string   $file   —  The filename where to write the data
array   $fields   —  Ordered array with the data
array   &$conf   —  The configuration of the dest CSV

[ Top ]


Documentation generated on Mon, 11 Mar 2019 15:43:21 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.