You are here

function barcode_postnet_encode in Barcode 6.2

Same name and namespace in other branches
  1. 7.2 plugins/postnet.inc \barcode_postnet_encode()
1 call to barcode_postnet_encode()
barcode_postnet_barcode in plugins/postnet.inc
@file Barcode plugin Postnet: Printed by U.S. Post Office on envelopes

File

plugins/postnet.inc, line 111
Barcode plugin Postnet: Printed by U.S. Post Office on envelopes

Code

function barcode_postnet_encode($barnumber, $settings) {
  $enc_table = array(
    "11000",
    "00011",
    "00101",
    "00110",
    "01001",
    "01010",
    "01100",
    "10001",
    "10010",
    "10100",
  );
  $sum = 0;
  $encstr = "";
  for ($i = 0; $i < strlen($barnumber); $i++) {
    $sum += (int) $barnumber[$i];
    $encstr .= $enc_table[(int) $barnumber[$i]];
  }
  if ($sum % 10 != 0) {
    $check = (int) (10 - $sum % 10);
  }
  $encstr .= $enc_table[$check];
  $encstr = "1" . $encstr . "1";
  return $encstr;
}