function BARCODE::_checkDigit in Barcode 6
4 calls to BARCODE::_checkDigit()
File
- ./
barcode.inc.php, line 1401
Class
Code
function _checkDigit($barnumber, $number) {
$csumTotal = 0;
// The checksum working variable starts at zero
// If the source message string is less than 12 characters long, we make it 12 characters
if (strlen($barnumber) < $number) {
$barnumber = str_pad($barnumber, $number, "0", STR_PAD_LEFT);
}
// Calculate the checksum value for the message
for ($i = 0; $i < strlen($barnumber); $i++) {
if ($i % 2 == 0) {
$csumTotal = $csumTotal + 3 * intval($barnumber[$i]);
}
else {
$csumTotal = $csumTotal + intval($barnumber[$i]);
}
}
// Calculate the checksum digit
//echo $csumTotal;
if ($csumTotal % 10 == 0) {
$checksumDigit = '';
}
else {
$checksumDigit = 10 - $csumTotal % 10;
}
return $barnumber . $checksumDigit;
}