Make multiple barcodes with simple script

Steynsk
Steynsk used Ask the Experts™
on
Hi Expert,

I've found this exelent working PHP script that makes the barcodes. I've found it at this page.

<?
include "Barcode39.php"; 
$bc = new Barcode39("123-ABC"); 
$bc->barcode_text_size = 5; 
$bc->barcode_bar_thick = 4; 
$bc->barcode_bar_thin = 2; 
$bc->draw();
?>

Open in new window


Would there be a simple way to make this script write multiple barcodes with different values in one page?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
The script above returns an image so to get multiple on one page you would need to have a script that returns an image based on parameterised input - something like this
<?php
include "Barcode39.php"; 
$label = isset($_GET['label']) ? $_GET['label'] : 'NO LABEL';
$size = isset($_GET['size']) ? $_GET['size'] : 5;
$thick = isset($_GET['thick']) ? $_GET['thick'] : 4;
$thin = isset($_GET['thin']) ? $_GET['thin'] : 2;

$bc = new Barcode39($label); 
$bc->barcode_text_size = $size; 
$bc->barcode_bar_thick = $thick; 
$bc->barcode_bar_thin = $thin; 
$bc->draw();

Open in new window

NB: Some hints for PHP script - don't use the short form of the script tag <? - rather use <?php
If your script contains only script then you can leave the closing tag off - this can prevent errors relating to blank characters after the closing tag.
You can now call multiple codes by passing parameters to the above script in an <img> tag like so
<img src="t1295.php?label=ABC-123" /><br/>
<img src="t1295.php?label=DEF-456" /><br/>
<img src="t1295.php?label=GHI-789" /><br/>
<img src="t1295.php?label=JKL-000" /><br/>

Open in new window

Working sample here

Commented:
Julian is correct and it should work in the same way as any streaming product with the IMG tag. For example:
http://support.idautomation.com/php-barcode/idautomation-code128.php?D=Testing123456
returns an image.
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Just create a new Barcode39 each time you need to. Put the codes you want in an array and loop through them:

include "Barcode39.php";
$codes = array("Code 1", "Code 2", "Code 3");
		
foreach ($codes as $code):
    $bc = new Barcode39($code); 
    $bc->barcode_text_size = 5; 
    $bc->barcode_bar_thick = 4; 
    $bc->barcode_bar_thin = 2; 
    $bc->draw();
endforeach;

Open in new window

Author

Commented:
Julian,

Thank you very much for the answer to my question and the advise.

Kind regards,

Steynsk
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial