PHP code example of janisvepris / gs1-decoder

1. Go to this page and download the library: Download janisvepris/gs1-decoder 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/ */

    

janisvepris / gs1-decoder example snippets




use JanisVepris\GS1Decoder\Decoder;
use Janisvepris\Gs1Decoder\ApplicationIdentifier\Gtin;

$barcode = '0112345678901234[FNC1]2140928049820384[FNC1]';
$decoder = new Decoder();

$decoded = $decoder->decode($barcode);
$decoded->hasIdentifier(Gtin::CODE);
$decoded->getIdentifier(Gtin::CODE)->getValue();



use JanisVepris\GS1Decoder\Decoder;
use Janisvepris\Gs1Decoder\ApplicationIdentifier\Gtin;
use Janisvepris\Gs1Decoder\IdentifierMap;

$barcode = '0112345678901234';

$decoder = new Decoder(new IdentifierMap([
    '01' => Gtin::class,
]));

// or

$decoder = new Decoder();
$decoder->setIdentifierMap(new IdentifierMap([
    '01' => Gtin::class,
]));

$decoded = $decoder->decode($barcode);



use JanisVepris\GS1Decoder\Decoder;

class MyGtinIdentifier extends SimpleIdentifier
{
    protected $code = '01';
    protected int $length = 99;
    protected string $englishTitle = 'My awesome title';
}

// Replace the default identifier class map with your own 
$decoder = new Decoder(new IdentifierMap([
    '01' => MyGtinIdentifier::class,
]));

// or add your own identifier class to the default map
$decoder = new Decoder();
$decoder->getIdentifierMap()
    ->addIdentifierClass('01', MyGtinIdentifier::class)