You are here

function BARCODE::_ean8Encode in Barcode 6

1 call to BARCODE::_ean8Encode()
BARCODE::_ean8Barcode in ./barcode.inc.php

File

./barcode.inc.php, line 1441

Class

BARCODE

Code

function _ean8Encode($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 = "";
  for ($i = 0; $i < strlen($barnumber); $i++) {
    $num = (int) $barnumber[$i];
    if ($i < 4) {
      $mfcStr .= $leftOdd[$num];
    }
    elseif ($i >= 4) {
      $prodStr .= $rightAll[$num];
    }
  }
  return $guards[0] . $mfcStr . $guards[1] . $prodStr . $guards[2];
}