violuke/php-barcodes

一组用于管理条形码的PHP类。

v1.0.2 2021-04-22 18:11 UTC

This package is auto-updated.

Last update: 2024-09-23 01:28:42 UTC


README

一个用于检查EAN8、EAN13、UPC和GTIN条形码是否有效的PHP类(基于校验码)。

Travis CI Packagist Packagist Packagist Packagist PHP 7 ready

https://packagist.org.cn/packages/violuke/php-barcodes

注意:该项目目前仅包含一些验证函数。我期望将来添加更多功能。

安装(使用composer)

composer require violuke/php-barcodes

用法

// 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()

待办事项

  • 条形码生成
  • GS1-128条形码生成和解析

鸣谢

  • 条形码验证函数基于Ferry Bouwhuis的工作。
  • 从hassel-it/php-barcodes分支添加了EAN受限格式。
  • 初始单元测试基于hassel-it/php-barcodes分支的工作。