for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace LWI\DeliveryTracking\Parser;
/**
* Class FixedWidthColumnsParser
*/
class FixedWidthColumnsParser
{
* @var array
protected $structure = [];
* FixedWidthColumnsParser constructor.
* @param $structure
public function __construct($structure)
$this->structure = $structure;
}
* @param $line
*
* @return array
public function parseLine($line)
$result = [];
$cursor = 0;
foreach ($this->structure as $field => $width) {
$fieldValue = trim(mb_substr($line, $cursor, $width));
if ($fieldValue !== '') {
$result[$field] = $fieldValue;
$cursor += $width;
return $result;
* @param $content
public function parseMultiLine($content)
$lines = explode("\n", $content);
$results = [];
foreach ($lines as $line) {
$lineData = $this->parseLine($line);
if (!empty($lineData)) {
$results[] = $lineData;
return $results;