PHPackages                             robsonala/php-complex-parser - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. robsonala/php-complex-parser

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

robsonala/php-complex-parser
============================

PHP Complex CSV parser

10PHP

Since Aug 29Pushed 7y agoCompare

[ Source](https://github.com/robsonala/php-complex-parser)[ Packagist](https://packagist.org/packages/robsonala/php-complex-parser)[ RSS](/packages/robsonala-php-complex-parser/feed)WikiDiscussions master Synced 4d ago

READMEChangelogDependenciesVersions (1)Used By (0)

PHP Complex CSV parser
======================

[](#php-complex-csv-parser)

Parse complex CSV to JSON

[![Build Status](https://camo.githubusercontent.com/15d5ebeed60a05113bfe5900217582f6a293265214648e5a926a4627dceed15b/68747470733a2f2f7472617669732d63692e6f72672f726f62736f6e616c612f7068702d636f6d706c65782d7061727365722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/robsonala/php-complex-parser)

---

Simple usage
------------

[](#simple-usage)

```
$str = 'CN1339361,,,,,
,Week 51 2017,Week 52 2017,Week 01 2018,Week 02 2018,Week 03 2018
Sales,1,5,6,9,1
Stock,1,7,1,2,4
Forecast,3,7,0,3,3
,,,,,
CN1339987,,,,,
,Week 51 2017,Week 52 2017,Week 01 2018,Week 02 2018,Week 03 2018
Sales,6,7,1,3,7
Stock,2,6,0,2,4
Forecast,5,0,2,2,4';

$settings = json_encode([
    'Header' => [
        'Global' => false,
        'Position' => [
            'Line' => 1
        ]
    ],
    'Block' => [
        'Transpose' => false,
        'Size' => 6
    ],
    'Columns' => [
        [
            'Type' => ColumnType::Single()->getValue(),
            'Name' => 'partcode',
            'Position' => [
                'Line' => 0,
                'Column' => 0
            ]
        ],
        [
            'Type' => ColumnType::Multiple()->getValue(),
            'Name' => 'sales',
            'KeepHeader' => false,
            'Position' => [
                'Line' => 3,
                'Range' => [1, null]
            ]
        ],
        [
            'Type' => ColumnType::Multiple()->getValue(),
            'Name' => 'stock',
            'KeepHeader' => false,
            'Position' => [
                'Search' => 'Stock',
                'SearchColumn' => 0,
                'Range' => [1, 4]
            ]
        ],
        [
            'Type' => ColumnType::Multiple()->getValue(),
            'Name' => 'fcast',
            'KeepHeader' => false,
            'Position' => [
                'Search' => 'Forecast',
                'SearchColumn' => 0,
                'HeaderMatch' => 'Week [0-9]{1,2} 2018'
            ]
        ]
    ]
]);

// Load CSV
$parser = new PHPComplexParser();
$parser->loadCsvStr($str);

// Load Settings
$parser->loadSettingsJson($settings);

$out = $parser->processData();
/*
$out =>
array(
    array(
        'partcode' => 'CN1339361',
        'sales' => array(1,7,1,2,4),
        'stock' => array(1,7,1,2),
        'fcast' => array(0,3,3)
    ),
    array(
        'partcode' => 'CN1339987',
        'sales' => array(2,6,0,2,4),
        'stock' => array(2,6,0,2),
        'fcast' => array(2,2,4)
    )
)
*/
```

---

Settings Options
----------------

[](#settings-options)

### General

[](#general)

NameDescriptionTypeIgnoreLinesBeginNumber of lines to be ignored at begin of the fileInteger### Header

[](#header)

NameDescriptionTypeGlobalWhere header line is located (TRUE = Global / FALSE = Block)BooleanPositionPosition of the header linePositionHeader### PositionHeader

[](#positionheader)

NameDescriptionTypeLineLine where header is placedInteger### Block

[](#block)

NameDescriptionTypeTransposeTranspose the block before process itBooleanSizeIf the blocks are fixed size you can split it by the number of linesIntegerBreakIf it's not fixed size you can select the type of block delimiterEnum BlockBreakBreakSearchValue to be find in specific BlockBreaksString/RegexBreakSearchColumnColumn position for BlockSearchInteger### Column

[](#column)

NameDescriptionTypeTypeType of parserEnum ColumnTypeNameName to be returned on out dataStringKeepHeaderShow the original header on out informationBooleanPositionPosition where the data will be extractedPositionColumn### PositionColumn

[](#positioncolumn)

NameDescriptionTypeLineLine where data will be extractedIntegerColumnColumn where the data will be extracted (for Single extractor)IntegerSearchInformation to be search and select the line (for Multiple extractor)String/SearchSearchColumnColumn position for 'Search'IntegerHeaderMatchUsing header to match the columns (for Multiple extractor)String/SearchRangeSelect data from a list of columns (for Multiple extractor)Array(integer, integer/null)---

Enumerators
-----------

[](#enumerators)

### BlockBreak

[](#blockbreak)

IDNameDescription1EmptyLineBreak block each empty line2MatchLastLineBreak block every time the extractor find a specific last line2MatchFirstLineBreak block every time the extractor find a specific first line### ColumnType

[](#columntype)

IDNameDescription1SingleSearch just single information from column/line1MultipleSearch multiple information from line

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/e14779ba8ca68f281abacc9b009ab3597cfb0478a27835841e311fd937a36da4?d=identicon)[robsonala](/maintainers/robsonala)

---

Tags

csvjsonparserphp

### Embed Badge

![Health badge](/badges/robsonala-php-complex-parser/health.svg)

```
[![Health](https://phpackages.com/badges/robsonala-php-complex-parser/health.svg)](https://phpackages.com/packages/robsonala-php-complex-parser)
```

###  Alternatives

[phpoffice/phpspreadsheet

PHPSpreadsheet - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine

13.9k293.5M1.3k](/packages/phpoffice-phpspreadsheet)[spatie/browsershot

Convert a webpage to an image or pdf using headless Chrome

5.2k32.1M102](/packages/spatie-browsershot)[smalot/pdfparser

Pdf parser library. Can read and extract information from pdf file.

2.7k34.5M216](/packages/smalot-pdfparser)[barryvdh/laravel-snappy

Snappy PDF/Image for Laravel

2.8k24.8M48](/packages/barryvdh-laravel-snappy)[openspout/openspout

PHP Library to read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way

1.1k57.6M131](/packages/openspout-openspout)[keboola/csv

Keboola CSV reader and writer

1451.8M21](/packages/keboola-csv)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
