條形碼生成器(從這裏取出http://www.barcodephp.com/en/userguide)的php代碼看起來像這樣。哪部分代碼必須在foreach循環中
我不知道哪個部分必須在foreach循環內從數組生成多個條形碼? $code->parse('1'); // Text
該行獲得1個值 - 在本例中爲編號1並生成條形碼。我需要生成數量陣列中的所有元素條碼
// Including all required classes
require_once('incl/class/BCGFontFile.php');
require_once('incl/class/BCGColor.php');
require_once('incl/class/BCGDrawing.php');
// Including the barcode technology
require_once('incl/class/BCGcode39.barcode.php');
// Loading Font
$font = new BCGFontFile('./incl/class/font/Arial.ttf', 18);
// The arguments are R, G, B for color.
$color_black = new BCGColor(0, 0, 0);
$color_white = new BCGColor(255, 255, 255);
$drawException = null;
try {
$code = new BCGcode39();
$code->setScale(2); // Resolution
$code->setThickness(30); // Thickness
$code->setForegroundColor($color_black); // Color of bars
$code->setBackgroundColor($color_white); // Color of spaces
$code->setFont($font); // Font (or 0)
$code->parse('1'); // Text
} catch(Exception $exception) {
$drawException = $exception;
}
/* Here is the list of the arguments
1 - Filename (empty : display on screen)
2 - Background color */
$drawing = new BCGDrawing('', $color_white);
if($drawException) {
$drawing->drawException($drawException);
} else {
$drawing->setBarcode($code);
$drawing->draw();
}
// Header that says it is an image (remove it if you save the barcode to a file)
header('Content-Type: image/png');
// Draw (or save) the image into PNG format.
$drawing->finish(BCGDrawing::IMG_FORMAT_PNG);