PHPackages                             decss/item-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. decss/item-parser

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

decss/item-parser
=================

Parse Items/Products with parameters or options from CSV. Display result as HTML table

1.2.0(4y ago)174MITPHPPHP &gt;=5.5

Since Oct 26Pushed 4y ago1 watchersCompare

[ Source](https://github.com/decss/item-parser)[ Packagist](https://packagist.org/packages/decss/item-parser)[ RSS](/packages/decss-item-parser/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (9)Used By (0)

ItemParser
==========

[](#itemparser)

ItemParser is a simple PHP class for parsing Products and other records with their parameters or options (like colors, sizes etc) from CSV, present results as array or display it as html table

[![ItemParser Preview](https://raw.githubusercontent.com/decss/item-parser/assets/ItemParserPromo.png)](https://raw.githubusercontent.com/decss/item-parser/assets/ItemParserPromo.png)

### Take a look at [live demo](http://217.16.18.253/item-parser/examples/)

[](#take-a-look-at-live-demo)

See the `examples` folder for usage examples

Features
--------

[](#features)

**Parser** features:

- Parse data from csv to array
- Display parse results in table view
- Parse parameters like `size`, `color`, `material`, `category`, etc from cells like `S; M; L; XL` to array of `[id => 1, value => "S"]` items
- Detect missing parameters and give an ability to replace or ignore it
- Configure each column type and order or skip it
- Search parameters by value or aliases
- Skip specified rows or columns

**Drawer** features:

- Select, change or skip each column manually
- Display parameters as tags
- Mark tags as `ignored`, `replaced` or `not found`
- Mark cell as `valid` or `invalid`
- Shorten links and image urls
- Shorten long text
- Hide valid, invalid or custom rows

Requirements
------------

[](#requirements)

As noted in `composer.json` production requirements:

- php &gt;= 5.5
- php mbstring extension
- php json extension
- php iconv extension
- parsecsv/php-parsecsv

Installation
------------

[](#installation)

Using Composer run the following on the command line:

```
composer require decss/item-parser

```

Include Composer's autoloader file in your PHP script:

```
require_once __DIR__ . '/vendor/autoload.php';
```

#### Without composer

[](#without-composer)

Not recommended. To use ItemParser, you have to add a `require 'itemparser.lib.php';` line. Note that you will need to require all ItemParser dependencies like `ParseCsv`.

Parser result
-------------

[](#parser-result)

Paeser result is an array of rows (lines). Each row matches the corresponding line in the CSV and generally looks as follows:

```
0 => [
    "row"    => 1,          // line number in CSV
    "valid"  => true,       // true if all row's Fields is valid, false if any is invalid
    "skip"   => false,      // true only if you skip this row by special method
    "fields" => []          // array of row fields (cells)
]
```

Skipped rows can be both valid (`"valid" => true`) or invalid (`"valid" => false`) and vice versa.

As mentioned above, `"fields"` is an array of Field items. Each Field can be different depending on its type, config and content. All row fields will be presented in result, even if Field was not parsed or was skipped or invalid - there is no matter.

#### Empty field

[](#empty-field)

This is an example of skipped or not configured Field:

```
14 => [
    "text"  => "cell text", // Original CSV cell text
    "name"  => null,        // Field name from Parser Fields config
    "type"  => null         // Field type
]
```

#### Text field

[](#text-field)

So there is 2 Field types: `text` and `param`. Here is example of configured `text` Field:

```
1 => [
    "text"  => "V_3J689910",
    "name"  => "item_sku",
    "type"  => "text",
    "valid" => true,        // true if Field is not required or required and have valid "value"
    "value" => "V_3J689910" // Unlike "text", "value" is the processed value of a cell.
]
```

`"value"` - is what you should to use instead of `"text"`

#### Param field and values

[](#param-field-and-values)

Next is "param" Field:

```
3 => [
    "text" => "Black; Not a color; Grey; ",
    "name" => "item_color",
    "type" => "param",
    "valid" => false,
    "value" => [
        0 => [
            "valid" => true,    // true if param was found in Field params
            "skip" => false,    // true if this value was skipped in Field missings config
            "replace" => false, // true if this value was replaced in Field missings config
            "id" => 1,          // Param ID, if it's value was found by in Field params
            "value" => "Black", // Param or Replaced param value
            "text" => "Black"   // Param text extracted from cell text value
        ],
        1 => [
            "valid" => false,
            "skip" => false,
            "replace" => false,
            "id" => null,
            "value" => null,
            "text" => "Not a color"
        ],
        2 => ["valid" => true, "skip" => false, "replace" => false, "id" => 3, "value" => "Grey", "text" => "Grey"]
    ]
]
```

So you can see that `"value"` of `param` Field is an array. Here is example of both found `[0,2]` and not found `[1]` colors. If there is 2 or more identical colors (ie `"Black; Red; Black"`) all fo them will be valid but duplicates will be skipped.

Usage
-----

[](#usage)

#### Parser usage

[](#parser-usage)

```
use ItemParser\Parser;

// 1. Init Parser and set CSV file path
$csvPath = 'file.csv';
$parser = new Parser($csvPath);

// 2. Config columns
$parser->textField('item_name')->required();
$parser->textField('item_sku')->required();
$parser->textField('item_price')->required();
$parser->textField('item_link');
$parser->textField('item_image1');
$parser->textField('item_image2');
// 2.1 Config param column
// Param array
$colors = [
    ['id' => 1, 'value' => 'Red'],
    ['id' => 2, 'value' => 'Green'],
    ['id' => 3, 'value' => 'Blue'],
    ['id' => 4, 'value' => 'Gold', 'alias' => ['Gold sand', 'Golden-Orange']],
];
// Param Missing - skip or replace colors, that was not found in $colors
$colorsMissing = [
    'Orange' => -1, //  Skip this color
    'Golden' => 4,  //  Replace "Golden" to "Gold" (id = 4)
];
$parser->paramField('item_color', [$colors, $colorsMissing])->required();

// 3. Run parse and get results
$result = $parser->parse();
```

#### Drawer usage

[](#drawer-usage)

```
use ItemParser\Drawer;

// Create Drawer and config columns (optional)
$drawer = new Drawer($parser, [
    'item_name' => ['title' => 'Product Name'],
    'item_link' => ['display' => 'link'],
    'item_image1' => ['display' => 'image'],
]);

// Display results
echo ''
    . '' . $drawer->head() . ''
    . '' . $drawer->body() . ''
    . '';
```

Detailed usage
--------------

[](#detailed-usage)

#### Create Parser and set content

[](#create-parser-and-set-content)

```
// Set CSV file path
$parser = new Parser('file.csv');
// or
$parser = new Parser;
$parser->setCsvPath('file.csv');
// also you can use preconfigured parseCsv class
$parseCsv = new \ParseCsv\Csv();
$parseCsv->limit = 5;
$parseCsv->delimiter = "\t";
$parser = new Parser('file.csv', $parseCsv);

// Set SCV content
$parser = new Parser;
$content = file_get_contents('file.csv');
$parser->setCsvContent($content);
```

You can access to `Csv()` instance of `ParseCsv` library and configure it directly:

```
$csvObj = $parser->getCsvObj();
$csvObj->delimiter = ';,';      // Set CSV rows delimiter characters
```

#### Configure columns

[](#configure-columns)

```
// Add text field
$parser->textField('column_name');
// Add required text field
$parser->textField('column2_name')->required();

// Add param field
$parser->paramField('item_size', [$sizes]);
// Add required param field with missing colors and set possible delimiters for params
$parser->paramField('item_color', [$colors, $colorsMissing])->required()->delimiters([';', ',', '/']);
```

See examples to get how arguments like `$colors` and `$colorsMissing` work

#### Configure parser options

[](#configure-parser-options)

```
// Skip first 2 rows
$parser->skipRows([0,1]);

// Skip columns and set order
$parser->fieldsOrder([
    0 => 'item_name',
    1 => 'item_sku',
    2 => 'item_price',
    3 => 'item_color',
    4 => 'item_size',
    // 5, 6 - skip
    7 => 'item_material',
    8 => 'item_desc',
    9 => 'item_link',
    10 => 'item_image1',
    11 => 'item_image2',
    12 => 'item_image3',
    // further will be skipped
]);
```

#### Parsing and results

[](#parsing-and-results)

```
// Do parsing and get results
$result = $parser->parse();

// Get results after parsing
$result = $parser->result();
```

#### Use Drawer

[](#use-drawer)

```
// Create Drawer and config it
$drawer = new Drawer($parser, [
    'item_name' => ['title' => 'Product Name'],
    'item_sku' => ['title' => 'Product SKU'],
    'item_price' => ['title' => 'Price'],
    'item_size' => ['title' => 'Sizes'],
    'item_color' => ['title' => 'Colors'],
    'item_desc' => ['title' => 'Description', 'display' => 'text'],
    'item_link' => ['display' => 'link'],
    'item_image1' => ['display' => 'image'],
    'item_image2' => ['display' => 'image'],
    'item_image3' => ['display' => 'image'],
]);

// Hide valid rows
$drawer->hideValid();
// Hide invalid rows
$drawer->hideInvalid();
// Hide custom rows
drawer->hideRows([0, 6, 7, 8]);

// Display missing selects
echo $drawer->missing();

// Display table column names
echo $drawer->head();
// Display table column names with Field selects
echo $drawer->head('select');

// Display table rows
echo $drawer->body();
```

Credits
-------

[](#credits)

- ItemParser is based on [ParseCsv](https://github.com/parsecsv/parsecsv-for-php) class.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~60 days

Recently: every ~75 days

Total

6

Last Release

1725d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/920603a588eddaf0a50f859d2867a128dbf29b2e4be394aeb4e62381ffc57a4d?d=identicon)[decss](/maintainers/decss)

---

Top Contributors

[![decss](https://avatars.githubusercontent.com/u/516637?v=4)](https://github.com/decss "decss (51 commits)")

---

Tags

csvcsv-convertercsv-parserparsecsvparserproductoptionsparsercsvparametersproductcsv parserparsecsvproduct parser

### Embed Badge

![Health badge](/badges/decss-item-parser/health.svg)

```
[![Health](https://phpackages.com/badges/decss-item-parser/health.svg)](https://phpackages.com/packages/decss-item-parser)
```

###  Alternatives

[faisalman/simple-excel-php

Easily parse / convert / write between Microsoft Excel XML / CSV / TSV / HTML / JSON / etc formats

582599.4k1](/packages/faisalman-simple-excel-php)[rodenastyle/stream-parser

PHP Multiformat Streaming Parser

443195.7k2](/packages/rodenastyle-stream-parser)[shuchkin/simplecsv

Parse and retrieve data from CSV files. Export data to CSV.

5192.4k](/packages/shuchkin-simplecsv)[csanquer/colibri-csv

Lightweight and performant CSV reader and writer library

16161.7k4](/packages/csanquer-colibri-csv)

PHPackages © 2026

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