Giter Club home page Giter Club logo

php-barcodes's Introduction

PHP Barcode

A PHP class for checking EAN8, EAN13, UPC and GTIN barcodes are valid (based on check digit).

Travis CI Packagist Packagist Packagist Packagist PHP 7 ready

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

php-barcodes's People

Contributors

dakorpar avatar violuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

php-barcodes's Issues

Conversion to GTIN14

if ($bc_validator->isValid()) {
  echo($bc_validator->getType(), 'Type');
  echo($bc_validator->getBarcode(), 'Barcode');
  echo($bc_validator->getGTIN14(), 'GTIN14');
}
Type: UPC
Barcode: 740668124518
GTIN14: 00740668124518

00740668124518 is incorrect, in GTIN14 it should be 0740668124518

getType() incorrectly reports UPC when provided with EAN

0700867967774 is an EAN and not a UPC. 700867967774 is UPC.

$barcode = new \violuke\Barcodes\BarcodeValidator("0700867967774");
‌violuke\Barcodes\BarcodeValidator::__set_state(array(
   'barcode' => '0700867967774',
   'type' => 'UPC',
   'gtin14' => '000000700867967774',
   'valid' => true,
))

‌‌$barcode->getType();
‌UPC

‌‌$barcode->getBarcode();
‌0700867967774

We're going to fix this ourselves now, will create PR shortly.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.