|
|
|
File: C:/usr/local/lib/php/blueshoes-4.2/core/util/Bs_CsvUtil.class.php
BlueShoes Application Framework - util
Bs_CsvUtil
Bs_Object | +-- Bs_CsvUtil
csv util class. csv = comma separated value.
|
private class Bs_CsvUtil extends Bs_Object
csv util class. csv = comma separated value.
features:- supports any separator char sequence, default is semicolon ";"- supports separator characters in the values. eg you use a ; as separator, your line may look likeblah;hello world;"foo";"foo;bar";"this is a ""string""";got it?;fooas you can see, the values can be in "quotes". if your text uses quotes itself as in the "string"example, they are escaped in ms-style with 2 quotes. and by using quotes we can even have yourseparator inside the text (example "foo;bar").- line breaks. a csv line may spread over multiple lines using crlf in a field value.see the checkMultiline param and the _checkMultiline() method.missing:- option to change quote char (") to something elsethanks to: steffen at hung dot chdependencies: none.
| Authors | |
| Version | 4.2.$id$ |
| Copyright | blueshoes.org |
|
| |
|
Methods inherited from Bs_Object |
| isex, isexception, tostring, tohtml, persist, unpersist, bs_object, bbsetoutput, bbawake, bbisawake, bbxmsg, bbxfunctionstart, bbxfunctionend, bbxecho, bbxvar, bbxvardump, bbforcetrace, bbbufferstart, bbbufferget, bbbufferendflush, bbbufferendclean |
|
|
|
Private Method Summary |
| void |
csvFileToArray(string $fullPath, [ string $separator ], string $trim, string $removeHeader, string $removeEmptyLines, string $checkMultiline)reads in a cvs-file and returns it as a 2-dim vector. |
| void |
csvStringToArray(string $string, [ string $separator ], string $trim, string $removeHeader, string $removeEmptyLines, string $checkMultiline)takes a csv-string and returns it as a 2-dim vector. |
| string |
_valToCsvHelper(string $val, string $separator, mixed $trimFunction)works on a string to include in a csv string/file. |
| array |
_checkMultiline(array $in)takes an array and combines elements (lines) if needed. |
|
Private Constant Summary |
| BS_CSVUTIL_VERSION |
>>4.0.$x$<< |
Warning: documentation is missing. |
|
Public Method Details |
Bs_CsvUtil |
|
public void Bs_CsvUtil( )
|
| |
Constructor.
|
| Returns |
void |
|
csvArrayToArray |
|
public array csvArrayToArray( string $array )
|
| |
reads in a cvs array and returns it as a 2-dim vector.
cvs = comma separated value. you can easily export that froman excel file for example. it looks like:headerCellOne;headerCellTwo;headerCellThreedataCellOne;dataCellTwo;dataCellThreeapple;peach;banana;grapefruitlinux;windows;mac1;2;3note 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 exampleabove, the fruits have 4 elements while the others just have 3. this is notcatched. ideally every sub-array would have 4 elements. this would have to beadded when needed, maybe with another param in the function call.
|
| Parameter |
|
| string |
$array |
|
|
(fullpath to the cvs file) |
|
| Returns |
array (2-dim vector. it may be an empty array if there is no data.) |
| Throws |
bool FALSE on any error. |
| See Also |
csvStringToArray() |
|
arrayToCsvString |
|
public string arrayToCsvString( array $array, [ string $separator, string $trim, string $removeEmptyLines ] )
|
| |
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;usaalanis morisette;rock;canadafalco;pop;austriatodo: add param "fill to fit max length"?
|
| Parameter |
|
|
|
| string |
$separator |
= >>';'<< |
|
(default is ';') |
|
|
| string |
$trim |
= >>'none'<< |
|
(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.) |
|
|
| string |
$removeEmptyLines |
= >>TRUE<< |
|
(default is TRUE. removes "lines" that have no value, would come out empty.) |
|
| Returns |
string (empty string if there is nothing at all) |
|
|
Private Method Details |
csvFileToArray |
|
private void csvFileToArray( string $fullPath, [ string $separator ], string $trim, string $removeHeader, string $removeEmptyLines, string $checkMultiline )
|
| |
reads in a cvs-file and returns it as a 2-dim vector.
|
| Parameter |
|
| string |
$fullPath |
|
|
(fullpath to the cvs file) |
|
|
| string |
$separator |
= >>';'<< |
|
(default is FALSE, see _checkMultiline()) |
|
|
| string |
$trim |
|
|
Warning: documentation is missing. |
|
|
| string |
$removeHeader |
|
|
Warning: documentation is missing. |
|
|
| string |
$removeEmptyLines |
|
|
Warning: documentation is missing. |
|
|
| string |
$checkMultiline |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
| See Also |
csvArrayToArray() |
|
csvStringToArray |
|
private void csvStringToArray( string $string, [ string $separator ], string $trim, string $removeHeader, string $removeEmptyLines, string $checkMultiline )
|
| |
takes a csv-string and returns it as a 2-dim vector.
|
| Parameter |
|
|
|
| string |
$separator |
= >>';'<< |
|
(default is FALSE, see _checkMultiline()) |
|
|
| string |
$trim |
|
|
Warning: documentation is missing. |
|
|
| string |
$removeHeader |
|
|
Warning: documentation is missing. |
|
|
| string |
$removeEmptyLines |
|
|
Warning: documentation is missing. |
|
|
| string |
$checkMultiline |
|
|
Warning: documentation is missing. |
|
| Returns |
void |
| See Also |
csvArrayToArray() |
|
_valToCsvHelper |
|
private string _valToCsvHelper( string $val, string $separator, mixed $trimFunction )
|
| |
works on a string to include in a csv string/file.
|
| Parameter |
|
|
|
|
|
| mixed |
$trimFunction |
|
|
(bool FALSE or 'rtrim' or so.) |
|
| Returns |
string |
| See Also |
arrayToCsvString() |
|
_checkMultiline |
|
private array _checkMultiline( array $in )
|
| |
takes an array and combines elements (lines) if needed.
|
| Parameter |
|
|
| Returns |
array |
|
|
Private Constant Details |
BS_CSVUTIL_VERSION
define( BS_CSVUTIL_VERSION, >>4.0.$x$<< )
Case: default: case sensitive
|
|
|
|
|
|
| PHPDoc 1.0beta |