PHP code example of violuke / php-barcodes

1. Go to this page and download the library: Download violuke/php-barcodes library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

violuke / php-barcodes example snippets


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

composer