You are here

function BARCODE::_i25Encode in Barcode 6

1 call to BARCODE::_i25Encode()
BARCODE::_i25Barcode in ./barcode.inc.php

File

./barcode.inc.php, line 986

Class

BARCODE

Code

function _i25Encode($barnumber) {
  $encTable = array(
    "NNWWN",
    "WNNNW",
    "NWNNW",
    "WWNNN",
    "NNWNW",
    "WNWNN",
    "NWWNN",
    "NNNWW",
    "WNNWN",
    "NWNWN",
  );
  $guards = array(
    "1010",
    "1101",
  );
  $len = strlen($barnumber);
  if ($len % 2 != 0) {
    $barnumber = $this
      ->_checkDigit($barnumber, $len);
    if ($len == strlen($barnumber) && substr($barnumber, -1) != '0') {
      $barnumber .= '0';
    }
  }
  $mfcStr = "";
  $widebar = str_pad("", $this->_n2w, "1", STR_PAD_LEFT);
  $widespc = str_pad("", $this->_n2w, "0", STR_PAD_LEFT);
  for ($i = 0; $i < strlen($barnumber); $i += 2) {
    $tmp = $encTable[(int) $barnumber[$i]];
    $tmp1 = $encTable[(int) $barnumber[$i + 1]];
    for ($j = 0; $j < strlen($tmp); $j++) {
      if ($tmp[$j] == 'N') {
        $mfcStr .= '1';
      }
      else {
        $mfcStr .= $widebar;
      }
      if ($tmp1[$j] == 'N') {
        $mfcStr .= '0';
      }
      else {
        $mfcStr .= $widespc;
      }
    }
  }
  return $guards[0] . $mfcStr . $guards[1];
}