1. Go to this page and download the library: Download decss/item-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/ */
decss / item-parser example snippets
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)
]
14 => [
"text" => "cell text", // Original CSV cell text
"name" => null, // Field name from Parser Fields config
"type" => null // Field type
]
1 => [
"text" => "V_3J689910",
"name" => "item_sku",
"type" => "text",
"valid" => true, // true if Field is not
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"]
]
]
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')->eld('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])->
// 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);