function BARCODE::_eanEncode in Barcode 6
1 call to BARCODE::_eanEncode()
File
- ./
barcode.inc.php, line 1616
Class
Code
function _eanEncode($barnumber) {
$leftOdd = array(
"0001101",
"0011001",
"0010011",
"0111101",
"0100011",
"0110001",
"0101111",
"0111011",
"0110111",
"0001011",
);
$leftEven = array(
"0100111",
"0110011",
"0011011",
"0100001",
"0011101",
"0111001",
"0000101",
"0010001",
"0001001",
"0010111",
);
$rightAll = array(
"1110010",
"1100110",
"1101100",
"1000010",
"1011100",
"1001110",
"1010000",
"1000100",
"1001000",
"1110100",
);
$encTable = array(
"000000",
"001011",
"001101",
"001110",
"010011",
"011001",
"011100",
"010101",
"010110",
"011010",
);
$guards = array(
"bab",
"ababa",
"bab",
);
$mfcStr = "";
$prodStr = "";
$encbit = $barnumber[0];
for ($i = 1; $i < strlen($barnumber); $i++) {
$num = (int) $barnumber[$i];
if ($i < 7) {
$even = substr($encTable[$encbit], $i - 1, 1) == 1;
if (!$even) {
$mfcStr .= $leftOdd[$num];
}
else {
$mfcStr .= $leftEven[$num];
}
}
elseif ($i >= 7) {
$prodStr .= $rightAll[$num];
}
}
return $guards[0] . $mfcStr . $guards[1] . $prodStr . $guards[2];
}