PHP code example of axelero / fixed-width

1. Go to this page and download the library: Download axelero/fixed-width library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

axelero / fixed-width example snippets


$config = [
    'a' => [
        'type' => 'string',
        'start' => 1,
        'end' => 5
    ],
    'b' => [
        'type' => 'integer',
        'start' => 6,
        'end' => 10
    ]
];

$obj = new FixedWidth($config);

$data = ['a' => 'xxx', 'b' => 42];
$string = $obj->writeLine($data); // 'xxx  00042'
 php

$config = [
'a' => [
    'type' => 'string',
    'start' => 3,
    'length' => 10
],
// numeric indexes of the config array will be ignored
[
    'type' => 'string',
    'start' => 13,
    'end' => 13
],
'b' => [
    'type' => 'string',
    'start' => 14,
    'end' => 17
]
];

$obj = new FixedWidth($config);

$line = '12345678901234567890';
$record = $obj->readLine($line); // ['a' => '3456789012','b' => '4567',]