function barcode_ean_encode in Barcode 6.2
Same name and namespace in other branches
- 7.2 plugins/ean.inc \barcode_ean_encode()
1 call to barcode_ean_encode()
- barcode_ean_barcode in plugins/
ean.inc
File
- plugins/
ean.inc, line 203 - Barcode plugin EAN-13: Used with consumer products internationally, 13 characters UPC-A: Used with consumer products in U.S., 12 characters ISBN: Used to mark books, 13 characters
Code
function barcode_ean_encode($barnumber) {
$left_odd = array(
"0001101",
"0011001",
"0010011",
"0111101",
"0100011",
"0110001",
"0101111",
"0111011",
"0110111",
"0001011",
);
$left_even = array(
"0100111",
"0110011",
"0011011",
"0100001",
"0011101",
"0111001",
"0000101",
"0010001",
"0001001",
"0010111",
);
$right_all = array(
"1110010",
"1100110",
"1101100",
"1000010",
"1011100",
"1001110",
"1010000",
"1000100",
"1001000",
"1110100",
);
$enc_table = array(
"000000",
"001011",
"001101",
"001110",
"010011",
"011001",
"011100",
"010101",
"010110",
"011010",
);
$guards = array(
"bab",
"ababa",
"bab",
);
$mfc_str = "";
$prod_str = "";
$encbit = $barnumber[0];
for ($i = 1; $i < strlen($barnumber); $i++) {
$num = (int) $barnumber[$i];
if ($i < 7) {
$even = substr($enc_table[$encbit], $i - 1, 1) == 1;
if (!$even) {
$mfc_str .= $left_odd[$num];
}
else {
$mfc_str .= $left_even[$num];
}
}
elseif ($i >= 7) {
$prod_str .= $right_all[$num];
}
}
return $guards[0] . $mfc_str . $guards[1] . $prod_str . $guards[2];
}