axelero/fixed-width
最新稳定版本:1.01
Composer 安装命令:
composer require axelero/fixed-width
包简介
A library to parse and build fixed-width strings
README 文档
README
A simple library to read and write fixed width file. It's a partial port from this python library, with the aim to be simple, stable and consistent.
Install
Via Composer
$ composer require axelero/fixed-width
Usage
You can read values from arbitrary strings:
$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',]
You can write arrays into fixed-width strings:
$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'
The possible configuration values for each field are:
- type: string|integer
- alignment: left|right (defaults to left for string, right for integers)
- padding: charachter to use to fill the missing space (defaults to '' for string, '0' for integers)
- default: what to write when an array field is missing (defaults to '' for string, '0' for integers)
Testing
$ phpunit
Contributing
You are welcome to send any PR. Please make sure the tests pass. Please try to keep the code PSR compliant (in the root of the project lies a .php_cs config file for that).
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 35.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-01-09