violuke / php-barcodes
A collection of PHP classes for managing barcodes.
Installs: 471 310
Dependents: 3
Suggesters: 0
Security: 0
Stars: 40
Watchers: 5
Forks: 25
Open Issues: 1
Requires
- php: ^5.0 || ^7.0 || ^8.0
Requires (Dev)
- phpunit/phpunit: ~4.8|~5.7|~8.0|~9.0
This package is auto-updated.
Last update: 2024-11-23 01:56:43 UTC
README
A PHP class for checking EAN8, EAN13, UPC and GTIN barcodes are valid (based on check digit).
https://packagist.org/packages/violuke/php-barcodes
Note: This project currently does nothing other than have some validation functions. I expect to add additional functionality in the future.
Installation (with composer)
composer require violuke/php-barcodes
Usage
// Class instantation $barcode = '5060411950139'; $bc_validator = new \violuke\Barcodes\BarcodeValidator($barcode); // Check barcode is in valid format if ($bc_validator->isValid()) { echo 'Valid :)'; } else { echo 'Invalid :('; } // Get the barcode type echo 'Barcode is in format of ' . $bc_validator->getType(); // Possible formats returned are: // (string) "GTIN" which equals constant \violuke\Barcodes\BarcodeValidator::TYPE_GTIN // (string) "EAN-8" which equals constant \violuke\Barcodes\BarcodeValidator::TYPE_EAN_8 // (string) "EAN" which equals constant \violuke\Barcodes\BarcodeValidator::TYPE_EAN // (string) "EAN Restricted" which equals constant \violuke\Barcodes\BarcodeValidator::TYPE_EAN_RESTRICTED // (string) "UPC" which equals constant \violuke\Barcodes\BarcodeValidator::TYPE_UPC // (string) "UPC Coupon Code" which equals constant \violuke\Barcodes\BarcodeValidator::TYPE_UPC_COUPON_CODE // Returns the barcode in GTIN-14 format $bc_validator->getGTIN14() // Returns the barcode as entered $bc_validator->getBarcode()
TODO:
- Barcode generation
- GS1-128 barcode generation and interpretation
Credits
- The barcode validation function was based on work by Ferry Bouwhuis.
- EAN Restricted format added from the hassel-it/php-barcodes fork.
- Initial unit tests based on work in the hassel-it/php-barcodes fork.