PHP code example of zol / fixed-column-width-parser
1. Go to this page and download the library: Download zol/fixed-column-width-parser 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/ */
zol / fixed-column-width-parser example snippets
use Zol\Parser\FixedColumnWidth\Parser;
$schema = [
'entry' => [ 'name' => 10 ]
];
$parser = new Parser($schema, 'import.dat');
$parser->parse();
[
// Ignored lines, null if none
// First line is indexed by 1
// Optionnal, null by default
'ignore' => [1, 8 , 9],
// Header line, null if missing
// Optionnal, null by default
'header' => ['field-name' => length, 'field-name' => length],
// Define entry schema
// Required
'entry' => ['field-name' => length, 'field-name' => length],
// Use header values as entry field names
// If true, entry field names will be replaced with header values
// Optionnal, false by default
'header-as-field-name' => false,
// Ignore empty line
// Optionnal, true by default
'ignore-empty-lines' => true,
// Multiple files in one
// If true, you must define separator
// Optionnal, default false,
'multiple' => false,
// Separator, only used if multiple is true
// Define files separator
'separator' => [
'field' => length, // Separator field
'values' => [ 'value', 'value'], // Field values considered as separator
'ignore' => true // Ignore separation line
]
]