You are here

function BARCODE::_c93Encode in Barcode 6

1 call to BARCODE::_c93Encode()
BARCODE::_c93Barcode in ./barcode.inc.php

File

./barcode.inc.php, line 228

Class

BARCODE

Code

function _c93Encode($barnumber) {
  $encTable = array(
    "0" => "100010100",
    "1" => "101001000",
    "2" => "101000100",
    "3" => "101000010",
    "4" => "100101000",
    "5" => "100100100",
    "6" => "100100010",
    "7" => "101010000",
    "8" => "100010010",
    "9" => "100001010",
    "A" => "110101000",
    "B" => "110100100",
    "C" => "110100010",
    "D" => "110010100",
    "E" => "110010010",
    "F" => "110001010",
    "G" => "101101000",
    "H" => "101100100",
    "I" => "101100010",
    "J" => "100110100",
    "K" => "100011010",
    "L" => "101011000",
    "M" => "101001100",
    "N" => "101000110",
    "O" => "100101100",
    "P" => "100010110",
    "Q" => "110110100",
    "R" => "110110010",
    "S" => "110101100",
    "T" => "110100110",
    "U" => "110010110",
    "V" => "110011010",
    "W" => "101101100",
    "X" => "101100110",
    "Y" => "100110110",
    "Z" => "100111010",
    "-" => "100101110",
    "." => "111010100",
    " " => "111010010",
    "\$" => "111001010",
    "/" => "101101110",
    "+" => "101110110",
    "%" => "110101110",
    "\$" => "100100110",
    "%" => "111011010",
    "/" => "111010110",
    "+" => "100110010",
    "*" => "101011110",
  );
  $mfcStr = "";
  $widebar = str_pad("", $this->_n2w, "1", STR_PAD_LEFT);
  $widespc = str_pad("", $this->_n2w, "0", STR_PAD_LEFT);
  $arr_key = array_keys($encTable);

  /// calculating C And K
  for ($j = 0; $j < 2; $j++) {
    $sum = 0;
    for ($i = strlen($barnumber); $i > 0; $i--) {
      $num = $barnumber[strlen($barnumber) - $i];
      if (preg_match("/[A-Z]+/", $num)) {
        $num = ord($num) - 55;
      }
      elseif ($num == '-') {
        $num = 36;
      }
      elseif ($num == '.') {
        $num = 37;
      }
      elseif ($num == ' ') {
        $num = 38;
      }
      elseif ($num == '$') {
        $num = 39;
      }
      elseif ($num == '/') {
        $num = 40;
      }
      elseif ($num == '+') {
        $num = 41;
      }
      elseif ($num == '%') {
        $num = 42;
      }
      elseif ($num == '*') {
        $num = 43;
      }
      $sum += $i * $num;
    }
    $barnumber .= trim($arr_key[(int) ($sum % 47)]);
  }
  $barnumber = "*" . $barnumber . "*";
  for ($i = 0; $i < strlen($barnumber); $i++) {
    $mfcStr .= $encTable[$barnumber[$i]];
  }
  $mfcStr .= '1';
  return $mfcStr;
}