GS1-128

GS1-128 barcode in PHP: Application Identifier element strings, length limit, code examples and SVG output

GS1-128 is CODE 128 carrying structured data: one or more Application Identifiers, each followed by its data field. AI 01 is a trade item number, 10 a batch, 17 an expiry date, and so on through the GS1 General Specifications.

Write the payload in the bracketed form, (ai)value(ai)value. The library parses it against the AI definitions, checks each field for length and character set, and inserts the FNC1 separators where a variable-length field needs one. Brackets are delimiters, so they cannot appear inside a value.

Type Token

ItemValue
Type tokenGS1128
Enum caseBarcodeType::GS1128
FamilyLinear
StandardGS1 General Specifications, ISO/IEC 15417
Class\Com\Tecnick\Barcode\Type\Linear\GsOneOneTwoEight

Input

ItemValue
Character setthe printable ASCII characters, in the bracketed element string form
Lengthup to 48 data characters
Checkper Application Identifier, where the definition specifies one
Extra parametersnone

Examples

A trade item number and a batch

<?php

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

$barcode = new \Com\Tecnick\Barcode\Barcode();
$bobj = $barcode->getBarcodeObj(
    type: 'GS1128',
    code: '(01)09501101020917(10)AB-123',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

echo $bobj->getInlineSvgCode();

GS1-128 barcode encoding (01)09501101020917(10)AB-123

Production and expiry dates

$bobj = $barcode->getBarcodeObj(
    type: 'GS1128',
    code: '(11)260920(17)280920',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

GS1-128 barcode encoding (11)260920(17)280920

Errors

These payloads raise \Com\Tecnick\Barcode\Exception:

PayloadMessage
01090150An Application Identifier in brackets is expected at position 0: 01090150
(01)0950110102091AThe data field of the Application Identifier (01) must be a number

See Also