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\Decoder;
use Janisvepris\Gs1Decoder\Enum\Gs1ApplicationIdentifier;
$decoder = new Decoder();
$decoded = $decoder->decode('0109521234543213' . '3103000189' . '17250630');
$decoded->hasIdentifier(Gs1ApplicationIdentifier::Gtin); // true
$decoded->getIdentifier(Gs1ApplicationIdentifier::Gtin)->getValue(); // '09521234543213'
$decoded->getIdentifier(Gs1ApplicationIdentifier::NetWeightKg)->getValue(); // 0.189
$decoded->getIdentifier(Gs1ApplicationIdentifier::ExpirationDate)->getValue(); // DateTime
$scanned = "0109521234543213" . "10ABC123" . "\x1d" . "17250630";
(new Decoder())->decode($scanned)->getIdentifierCount(); // 2 - AI 10 ate the rest
(new Decoder())->setDelimiter("\x1d")->decode($scanned)->getIdentifierCount(); // 3 - correct
$decoded->getRawValue(); // the string that was decoded
$decoded->getIdentifierCount(); // how many identifiers were found
$decoded->getAllIdentifiers(); // ApplicationIdentifierInterface[]
$decoded->toArray(); // plain nested array, safe to json_encode
$identifier->getCode(); // Gs1ApplicationIdentifier case
$identifier->getValue(); // typed value - see below
$identifier->getRawValue(); // the characters as they appeared in the barcode
$identifier->getEnglishTitle(); // e.g. 'Net weight, KG'
use Janisvepris\Gs1Decoder\ApplicationIdentifier\Gtin;
use Janisvepris\Gs1Decoder\ApplicationIdentifier\ExpirationDate;
use Janisvepris\Gs1Decoder\Decoder\Decoder;
use Janisvepris\Gs1Decoder\Enum\Gs1ApplicationIdentifier;
use Janisvepris\Gs1Decoder\IdentifierMap\IdentifierMap;
$decoder = new Decoder(new IdentifierMap([
Gs1ApplicationIdentifier::Gtin->value => Gtin::class,
Gs1ApplicationIdentifier::ExpirationDate->value => ExpirationDate::class,
]));
use Janisvepris\Gs1Decoder\ApplicationIdentifier\Abstract\SimpleIdentifier;
use Janisvepris\Gs1Decoder\Decoder\Decoder;
use Janisvepris\Gs1Decoder\Enum\Gs1ApplicationIdentifier;
class MyGtin extends SimpleIdentifier
{
protected Gs1ApplicationIdentifier $code = Gs1ApplicationIdentifier::Gtin;
protected int $length = 14;
protected string $englishTitle = 'GTIN, our wording';
}
// addIdentifierClass() throws DuplicateIdentifierCodeException if the code is already
// mapped, so remove the shipped class before swapping yours in
$decoder = new Decoder();
$decoder->getIdentifierMap()
->removeIdentifierClass(Gs1ApplicationIdentifier::Gtin)
->addIdentifierClass(Gs1ApplicationIdentifier::Gtin, MyGtin::class);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.