Exponential Basic 2.4.0.1 Exponential Basic CMS — PHP Class Reference

Public Member Functions | List of all members
eZCSVImport Class Reference

## Public Member Functions
| eZCSVImport ()
| csvFileToArray ($fullPath, $separator=';', $trim='none', $removeHeader=FALSE, $removeEmptyLines=FALSE, $checkMultiline=FALSE)
| csvStringToArray ($string, $separator=';', $trim='none', $removeHeader=FALSE, $removeEmptyLines=FALSE, $checkMultiline=FALSE)
| csvArrayToArray ($array, $separator=';', $trim='none', $removeHeader=FALSE, $removeEmptyLines=FALSE)
| arrayToCsvString ($array, $separator=';', $trim='none', $removeEmptyLines=TRUE)
| _valToCsvHelper ($val, $separator, $trimFunction)
| _checkMultiline ($in)

## Detailed Description

Definition at line 32 of file ezcsvimport.php.

## Member Function Documentation

## ◆ _checkMultiline()

eZCSVImport::_checkMultiline | ( |  | $in | ) |

takes an array and combines elements (lines) if needed. @access private

Parameters

  array | $in |

Returns
  array

Definition at line 326 of file ezcsvimport.php.

References $ret.

Referenced by csvFileToArray(), and csvStringToArray().

## ◆ _valToCsvHelper()

eZCSVImport::_valToCsvHelper | ( |  | $val,
|  |  | $separator,
|  |  | $trimFunction
| ) |  |

works on a string to include in a csv string/file. @access private

Parameters

  string | $val |
  string | $separator |
  mixed | $trimFunction | (bool FALSE or 'rtrim' or so.)

Returns
  string

See also
  arrayToCsvString() and others.

Definition at line 293 of file ezcsvimport.php.

References $separator.

Referenced by arrayToCsvString().

## ◆ arrayToCsvString()

eZCSVImport::arrayToCsvString | ( |  | $array,
|  |  | $separator = `';'`,
|  |  | $trim = `'none'`,
|  |  | $removeEmptyLines = `TRUE`
| ) |  |

takes an array and creates a csv string from it.

the given param $array may be a simple 1-dim array like this: $arr = array('madonna', 'alanis morisette', 'falco'); that will result in the string: "madonna;alanis morisette;falco"

if the param is a 2-dim array, it goes like this: $arr = array( array('madonna', 'pop', 'usa'), array('alanis morisette', 'rock', 'canada'), array('falco', 'pop', 'austria'), ); result: madonna;pop;usa alanis morisette;rock;canada falco;pop;austria

todo: add param "fill to fit max length"?

@access public

Parameters

  array | $array | (see above)
  string | $separator | (default is ';')
  string | $trim | (if we should trim the cells, default is 'none', can also be 'left', 'right' or 'both'. 'none' kinda makes it faster, omits many function calls, remember that.)
  bool | $removeEmptyLines | (default is TRUE. removes "lines" that have no value, would come out empty.)

Returns
  string (empty string if there is nothing at all)

Definition at line 239 of file ezcsvimport.php.

References $ret, $separator, and _valToCsvHelper().

## ◆ csvArrayToArray()

eZCSVImport::csvArrayToArray | ( |  | $array,
|  |  | $separator = `';'`,
|  |  | $trim = `'none'`,
|  |  | $removeHeader = `FALSE`,
|  |  | $removeEmptyLines = `FALSE`
| ) |  |

reads in a cvs array and returns it as a 2-dim vector.

cvs = comma separated value. you can easily export that from an excel file for example. it looks like:

headerCellOne;headerCellTwo;headerCellThree dataCellOne;dataCellTwo;dataCellThree apple;peach;banana;grapefruit linux;windows;mac 1;2;3

note I: all returned array elements are strings even if the values were numeric. note II: it may be that one array has another array-length than another. in the example above, the fruits have 4 elements while the others just have 3. this is not catched. ideally every sub-array would have 4 elements. this would have to be added when needed, maybe with another param in the function call.

@access public pseudostatic

Parameters

  string | $fullPath | (fullpath to the cvs file)
  array | $array | (hash or vector where the values are the csv lines)
  string | $separator | (cell separator, default is ';')
  string | $trim | (if we should trim the cells, default is 'none', can also be 'left', 'right' or 'both'. 'none' kinda makes it faster, omits many function calls, remember that.)
  bool | $removeHeader | (default is FALSE. would remove the first line which usually is the title line.)
  bool | $removeEmptyLines | (default is FALSE. would remove empty lines, that is, lines where the cells are empty. white spaces count as empty aswell.)

Returns
  array (2-dim vector. it may be an empty array if there is no data.)

Exceptions

  bool | FALSE on any error.

See also
  csvStringToArray()

Definition at line 121 of file ezcsvimport.php.

References $offset, $ret, and $separator.

Referenced by csvFileToArray(), and csvStringToArray().

## ◆ csvFileToArray()

eZCSVImport::csvFileToArray | ( |  | $fullPath,
|  |  | $separator = `';'`,
|  |  | $trim = `'none'`,
|  |  | $removeHeader = `FALSE`,
|  |  | $removeEmptyLines = `FALSE`,
|  |  | $checkMultiline = `FALSE`
| ) |  |

reads in a cvs-file and returns it as a 2-dim vector.

Parameters

  string | $fullPath | (fullpath to the cvs file)
  bool | $checkMultiline | (default is FALSE, see _checkMultiline())

See also
  csvArrayToArray()

Definition at line 48 of file ezcsvimport.php.

References $separator, _checkMultiline(), and csvArrayToArray().

## ◆ csvStringToArray()

eZCSVImport::csvStringToArray | ( |  | $string,
|  |  | $separator = `';'`,
|  |  | $trim = `'none'`,
|  |  | $removeHeader = `FALSE`,
|  |  | $removeEmptyLines = `FALSE`,
|  |  | $checkMultiline = `FALSE`
| ) |  |

takes a csv-string and returns it as a 2-dim vector.

Parameters

  string | $string |
  bool | $checkMultiline | (default is FALSE, see _checkMultiline())

See also
  csvArrayToArray()

Definition at line 72 of file ezcsvimport.php.

References $separator, _checkMultiline(), and csvArrayToArray().

## ◆ eZCSVImport()

eZCSVImport::eZCSVImport | ( |  | ) |

Constructor.

Definition at line 38 of file ezcsvimport.php.

The documentation for this class was generated from the following file:

- ezcsvimport.php

Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.