Download the PHP package econic/csvreader without Composer
On this page you can find all versions of the php package econic/csvreader. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package csvreader
CsvReader
CsvReader is a unit-tested PHP composer package with a utility class that reads your csv data and converts it into an associative two-dimensional array. Everything is configurable and many options and even modifiers can do the work for you...
License
CsvReader is released under the MIT license
Usage
Usage couldn't be simpler: just set the source, configure your options & get the result.
minimum configuration
result
With this you can easily iterate over your result:
Or even more convenient, when you set a key for your values (see below to learn how):
Characters
CSVreader has plenty of options to offer. You don't have to use any of them and you can use all of them at once if you want. Just as you like. Just use the respective setters/adders on the CSVreader object.
All setters/adders return the CSVreader object for easy chaining.
source
The source given as string. It contains the CSV data you want to get parsed.
Type: String
Default: ''
delimiter
The delimiter in the csv data. Want a semicolon here? No problem...
Type: String
Default: ','
newline
The newline character in the csv data. You don't break lines? Ok then... how about a dash?
Type: String
Default: "\n"
enclosure
The enclosure character in the csv data. Useful when your values contain the delimiter or the newline character. Just wrap your whole value with the enclosure caracter.
Type: String
Default: '"'
escape
The escape character in the csv data. Ok now you have " as enclosure character but your value contains a " ... Just prefix it with the escape character!
Type: String
Default: '\'
Options
You can configure even more with CSVreader, like the keys, modifiers, a global trim, ...
trim
If the values should be trimmed after parsing. Turned on by default. Will be executed before the modifiers.
Type: Boolean
Default: true
keys
Change the keys if you want to access the values via their respective attribute names.
Type1: Integer, Type2: String
Add multiple keys at once like so
Type: Array
Reset the keys whenever necessary
modifiers
Let's say the first value in every line of your csv is a title. It saved like "-v-a-l-u-e-" but your result should be like "VALUE". Just add a modifier at your chosen key and let the reader to its work. First parameter is the position of your value (0 based) or, if you chose another key for the value, your key.
Type1: Integer/String, Type2: Callable
Done. Every value will have its dashes removed and converted to uppercase. Of course you can do extremely intense stuff here. And you can stack the modifiers. As many as you want. They will be executed in the order you added them.
If you want to remove the modifiers after you added them, you can reset the modifiers of one key or all modifiers. Use
to remove all modifiers or
to remove just the modifiers registered for the title value.