Home > Software design >  remove first and last character from CODABAR laravel
remove first and last character from CODABAR laravel

Time:08-11

I am using laravel package to generate barcode. it successfully generates the code. but when i scan the barcode. it adds A and B first and the last of the barcode number.

if the number is 12345 it generates A12345A

Package I am using is package link

<center > {!! DNS1D::getBarcodeSVG($barcode->barcode, 'CODABAR', .7,25,'black',true) !!}</center>

CodePudding user response:

The format of CODEBAR is Here. You will note that as part of the format it adds A/B/C/D as start and stop symbols. They are part of the barcode.

To make the logic clear, here is a simple approach

$x = 'A12345A';
// remove last char
$x = substr ($x,0,-1);
//remove first char
$x = substr ($x, 1);

If you want it more compact you can use preg_replace

$x = 'A12345B';
$x = preg_replace ('!\D!','',$x);

Here ! is a delimiter. \D matches a non-digit character so it will take care of A-D and will not remove anything else.

CodePudding user response:

just briefly reviewed the library and it looks as though you can choose different types of barcodes to generate. For example to generate a EAN8 / EAN13 barcodes using this

echo DNS1D::getBarcodeHTML('4445', 'EAN8');
echo DNS1D::getBarcodeHTML('4445', 'EAN13');

Unless you actually need the CODABAR format (which has the termination characters A-D) use a different barcode model

  • Related