mehr-it / data-interchange-format
Data interchange format (DIF) writer
1.0.1
2020-01-20 13:50 UTC
Requires
- php: >=7.2.0
- ext-mbstring: *
- mehr-it/php-decimals: ^2.1
- thecodingmachine/safe: ^0.1.16
Requires (Dev)
- phpunit/phpunit: ^7.4|^8.0
This package is auto-updated.
Last update: 2024-10-21 00:42:05 UTC
README
This package implements a simple data interchange format (DIF) writer.
Usage
To create a DIF file, columns with data types have to be specified and the data has to be passed as array to the writer:
(new DifWriter())
->columns([
'Text' => DifWriter::TYPE_STRING,
'Number' => DifWriter::TYPE_NUMERIC,
])
->data([
[
'Text' => 'hello',
'Number' => 1,
],
[
'Text' => 'this is me',
'Number' => -3.5,
],
])
->writeTo($target)
Input/output encoding may be specified as well as the linebreak to use using the corresponding setter functions of the writer class.
By default the column headers are output as first line. To disable column header output, simply
pass false
as second argument to the columns()
method:
$writer->columns([
'Text' => DifWriter::TYPE_STRING,
'Number' => DifWriter::TYPE_NUMERIC,
], false);