Skip to content
PHP Logo

What are best practices for passing FNC3 characters to the Code 128 barcode in PHP?

When passing FNC3 characters to the Code 128 barcode in PHP, it is important to properly encode the special characters to ensure they are correctly interpreted by the barcode scanner. One common approach is to use the ASCII control character for FNC3 (ASCII code 131) and include it within the barcode data. This ensures that the FNC3 character is properly recognized by the scanner.

php
// Barcode data with FNC3 character encoded as ASCII control character
$barcodeData = "123456" . chr(131) . "7890";

// Generate the barcode using Code 128 format
$barcode = new TCPDFBarcode($barcodeData, 'C128');

// Output the barcode as an image
echo $barcode->getBarcodeHTML(2, 30, 'black');