2017 © Pedro Peláez
 

library fixed-width-file

Read and Write fixed width files

image

oliverde8/fixed-width-file

Read and Write fixed width files

  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

PHPLib-Fixed-Width-File

Allows easy Read(not yet) and write of fixed width file., (*1)

Latest Stable Version Total Downloads Latest Unstable Version License, (*2)

They are not nice, they are not easy to read but sometimes you just need them., (*3)

Howto

Firs let's create our file :, (*4)

$writer = new Writer('/tmp/file.txt', ' ', STR_PAD_LEFT);

First parameter is the name of the file to write Then we have the padding character, by default it is empty. Last we have the direction to pad. right or left., (*5)

Now we will declare our columns :, (*6)

$writer->getHeader()
    ->addColumn(4, 'year')
    ->addColumn(2, 'month')
    ->addColumn(2, 'day')
    ->addColumn(20, 'name')
    ->addColumn(100, 'description')

Once all this is done we can add data :, (*7)

// First line
$data = array();
$data['year'] = 2016;
$data['month'] = 02;
$data['day'] = 15;
$data['description'] = "This is a description" ;
$writer->writeLine($data);

// second line
$data = array();
$data['year'] = 2016;
$data['month'] = 02;
$data['day'] = 1;
$data['description'] = "This is a description2" ;
$writer->writeLine($data);

End finish the write, (*8)

$writer->terminate():

This will create a file looking like this :, (*9)

20160215This is a description
201602 1This is a description2

Known Issues

  • None

The library will write every line as it comes, it was built for handling huge amounts of data and therfore doesen't have a mode where it can write everything at once at the end., (*10)

Todo

  • Support reading : The same way the files are written we can read them once we have the necessary header informations.

The Versions

15/02 2016

dev-master

9999999-dev

Read and Write fixed width files

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

03/04 2015

1.0.0

1.0.0.0

Read and Write fixed width files

  Sources   Download

MIT

The Requires

  • php >=5.3.0