mehr-it/data-interchange-format

Data interchange format (DIF) writer

1.0.1 2020-01-20 13:50 UTC

This package is auto-updated.

Last update: 2024-11-21 00:54:51 UTC


README

Latest Version on Packagist Build Status

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);