UPC-A

UPC-A barcode in PHP: 12 digit input, check digit, add-on symbols, code examples and SVG output

The twelve-digit North American retail symbol, and the oldest of this family: the first UPC-A was scanned in 1974. It is an EAN-13 with a leading zero, and the library encodes it as one, which is why getExtendedCode() returns thirteen digits.

Type Token

ItemValue
Type tokenUPCA
Enum caseBarcodeType::UPCA
FamilyLinear
StandardISO/IEC 15420, GS1 General Specifications
Class\Com\Tecnick\Barcode\Type\Linear\UpcA

Input

ItemValue
Character setdigits, plus + to introduce an add-on
Length11 digits, or 12 with a valid check digit
Checkmodulo 10, appended when the payload is 11 digits and verified when it is 12
Extra parametersnone

Examples

A product code

<?php

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

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

echo $bobj->getInlineSvgCode();

UPC-A barcode encoding 72527273070

With a five-digit add-on

$bobj = $barcode->getBarcodeObj(
    type: 'UPCA',
    code: '72527273070+12345',
    width: -3,
    height: -30,
    color: 'black',
    padding: [0, 0, 0, 0],
)->setBackgroundColor('white');

UPC-A barcode encoding 72527273070+12345

Errors

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

PayloadMessage
1234567890AInput code must be a number
12345678901234The code is too long: 14 digits (maximum 12 for UPCA)

See Also