Open Barcode for PHP
A Composer library with PSR-4 autoloading and PHPUnit as a development-only dependency.
Install
composer require openbarcode/openbarcodeGenerate a barcode
use OpenBarcode\Linear\UPC;
$bars = (new UPC("03600029145"))->barcode(); // 95 modulesThe 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.
<?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<?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.