Open Barcode for PHP

A Composer library with PSR-4 autoloading and PHPUnit as a development-only dependency.

Package registryPackagist
RuntimePHP 8.1 or newer
LicenseApache-2.0

Install

Installbash
composer require openbarcode/openbarcode

Generate a barcode

Examplephp
use OpenBarcode\Linear\UPC;
$bars = (new UPC("03600029145"))->barcode(); // 95 modules

The example encodes UPC-A 03600029145, which gets check digit 2 and produces 95 modules. The same input gives the same modules in every Open Barcode library.

More examples

Each example uses the same modules as the tests, so the output matches the other languages.

Three barcode typesphp
<?php
use OpenBarcode\Linear\{UPC, EAN, Code39};

$upc = (new UPC("03600029145"))->barcode();     // 95 modules
$ean = (new EAN("400638133393"))->barcode();    // 95 modules
$code39 = (new Code39("CODE39"))->barcode();    // 103 modules
Wrong check digitphp
<?php
use OpenBarcode\Linear\UPC;

try {
    new UPC("036000291453"); // the check digit should be 2
} catch (InvalidArgumentException $e) {
    echo $e->getMessage();
}

Source and tests

The source, tests and release workflow are in the PHP repository on GitHub.

Other languages