96 switch (strtoupper(
$type)) {
214 $this->barcode_array =
false;
219 $this->barcode_array = $arrcode;
231 $chr[
'0'] =
'111221211';
232 $chr[
'1'] =
'211211112';
233 $chr[
'2'] =
'112211112';
234 $chr[
'3'] =
'212211111';
235 $chr[
'4'] =
'111221112';
236 $chr[
'5'] =
'211221111';
237 $chr[
'6'] =
'112221111';
238 $chr[
'7'] =
'111211212';
239 $chr[
'8'] =
'211211211';
240 $chr[
'9'] =
'112211211';
241 $chr[
'A'] =
'211112112';
242 $chr[
'B'] =
'112112112';
243 $chr[
'C'] =
'212112111';
244 $chr[
'D'] =
'111122112';
245 $chr[
'E'] =
'211122111';
246 $chr[
'F'] =
'112122111';
247 $chr[
'G'] =
'111112212';
248 $chr[
'H'] =
'211112211';
249 $chr[
'I'] =
'112112211';
250 $chr[
'J'] =
'111122211';
251 $chr[
'K'] =
'211111122';
252 $chr[
'L'] =
'112111122';
253 $chr[
'M'] =
'212111121';
254 $chr[
'N'] =
'111121122';
255 $chr[
'O'] =
'211121121';
256 $chr[
'P'] =
'112121121';
257 $chr[
'Q'] =
'111111222';
258 $chr[
'R'] =
'211111221';
259 $chr[
'S'] =
'112111221';
260 $chr[
'T'] =
'111121221';
261 $chr[
'U'] =
'221111112';
262 $chr[
'V'] =
'122111112';
263 $chr[
'W'] =
'222111111';
264 $chr[
'X'] =
'121121112';
265 $chr[
'Y'] =
'221121111';
266 $chr[
'Z'] =
'122121111';
267 $chr[
'-'] =
'121111212';
268 $chr[
'.'] =
'221111211';
269 $chr[
' '] =
'122111211';
270 $chr[
'$'] =
'121212111';
271 $chr[
'/'] =
'121211121';
272 $chr[
'+'] =
'121112121';
273 $chr[
'%'] =
'111212121';
274 $chr[
'*'] =
'121121211';
276 $code = strtoupper($code);
281 if ($code ===
false) {
289 $code =
'*'.$code.
'*';
291 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
293 $clen = strlen($code);
294 for ($i = 0; $i < $clen; ++$i) {
296 if(!isset($chr[$char])) {
300 for ($j = 0; $j < 9; ++$j) {
306 $w = $chr[$char]{$j};
307 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
308 $bararray[
'maxw'] += $w;
311 $bararray[
'bcode'][$k] = array(
't' =>
false,
'w' => 1,
'h' => 1,
'p' => 0);
312 $bararray[
'maxw'] += 1;
326 chr(0) =>
'%U', chr(1) =>
'$A', chr(2) =>
'$B', chr(3) =>
'$C',
327 chr(4) =>
'$D', chr(5) =>
'$E', chr(6) =>
'$F', chr(7) =>
'$G',
328 chr(8) =>
'$H', chr(9) =>
'$I', chr(10) =>
'$J', chr(11) =>
'£K',
329 chr(12) =>
'$L', chr(13) =>
'$M', chr(14) =>
'$N', chr(15) =>
'$O',
330 chr(16) =>
'$P', chr(17) =>
'$Q', chr(18) =>
'$R', chr(19) =>
'$S',
331 chr(20) =>
'$T', chr(21) =>
'$U', chr(22) =>
'$V', chr(23) =>
'$W',
332 chr(24) =>
'$X', chr(25) =>
'$Y', chr(26) =>
'$Z', chr(27) =>
'%A',
333 chr(28) =>
'%B', chr(29) =>
'%C', chr(30) =>
'%D', chr(31) =>
'%E',
334 chr(32) =>
' ', chr(33) =>
'/A', chr(34) =>
'/B', chr(35) =>
'/C',
335 chr(36) =>
'/D', chr(37) =>
'/E', chr(38) =>
'/F', chr(39) =>
'/G',
336 chr(40) =>
'/H', chr(41) =>
'/I', chr(42) =>
'/J', chr(43) =>
'/K',
337 chr(44) =>
'/L', chr(45) =>
'-', chr(46) =>
'.', chr(47) =>
'/O',
338 chr(48) =>
'0', chr(49) =>
'1', chr(50) =>
'2', chr(51) =>
'3',
339 chr(52) =>
'4', chr(53) =>
'5', chr(54) =>
'6', chr(55) =>
'7',
340 chr(56) =>
'8', chr(57) =>
'9', chr(58) =>
'/Z', chr(59) =>
'%F',
341 chr(60) =>
'%G', chr(61) =>
'%H', chr(62) =>
'%I', chr(63) =>
'%J',
342 chr(64) =>
'%V', chr(65) =>
'A', chr(66) =>
'B', chr(67) =>
'C',
343 chr(68) =>
'D', chr(69) =>
'E', chr(70) =>
'F', chr(71) =>
'G',
344 chr(72) =>
'H', chr(73) =>
'I', chr(74) =>
'J', chr(75) =>
'K',
345 chr(76) =>
'L', chr(77) =>
'M', chr(78) =>
'N', chr(79) =>
'O',
346 chr(80) =>
'P', chr(81) =>
'Q', chr(82) =>
'R', chr(83) =>
'S',
347 chr(84) =>
'T', chr(85) =>
'U', chr(86) =>
'V', chr(87) =>
'W',
348 chr(88) =>
'X', chr(89) =>
'Y', chr(90) =>
'Z', chr(91) =>
'%K',
349 chr(92) =>
'%L', chr(93) =>
'%M', chr(94) =>
'%N', chr(95) =>
'%O',
350 chr(96) =>
'%W', chr(97) =>
'+A', chr(98) =>
'+B', chr(99) =>
'+C',
351 chr(100) =>
'+D', chr(101) =>
'+E', chr(102) =>
'+F', chr(103) =>
'+G',
352 chr(104) =>
'+H', chr(105) =>
'+I', chr(106) =>
'+J', chr(107) =>
'+K',
353 chr(108) =>
'+L', chr(109) =>
'+M', chr(110) =>
'+N', chr(111) =>
'+O',
354 chr(112) =>
'+P', chr(113) =>
'+Q', chr(114) =>
'+R', chr(115) =>
'+S',
355 chr(116) =>
'+T', chr(117) =>
'+U', chr(118) =>
'+V', chr(119) =>
'+W',
356 chr(120) =>
'+X', chr(121) =>
'+Y', chr(122) =>
'+Z', chr(123) =>
'%P',
357 chr(124) =>
'%Q', chr(125) =>
'%R', chr(126) =>
'%S', chr(127) =>
'%T');
359 $clen = strlen($code);
360 for ($i = 0 ; $i < $clen; ++$i) {
361 if (ord($code{$i}) > 127) {
364 $code_ext .= $encode[$code{$i}];
377 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
378 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
379 'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
380 'W',
'X',
'Y',
'Z',
'-',
'.',
' ',
'$',
'/',
'+',
'%');
382 $clen = strlen($code);
383 for ($i = 0 ; $i < $clen; ++$i) {
384 $k = array_keys($chars, $code{$i});
400 $chr[
'0'] =
'131112';
401 $chr[
'1'] =
'111213';
402 $chr[
'2'] =
'111312';
403 $chr[
'3'] =
'111411';
404 $chr[
'4'] =
'121113';
405 $chr[
'5'] =
'121212';
406 $chr[
'6'] =
'121311';
407 $chr[
'7'] =
'111114';
408 $chr[
'8'] =
'131211';
409 $chr[
'9'] =
'141111';
410 $chr[
'A'] =
'211113';
411 $chr[
'B'] =
'211212';
412 $chr[
'C'] =
'211311';
413 $chr[
'D'] =
'221112';
414 $chr[
'E'] =
'221211';
415 $chr[
'F'] =
'231111';
416 $chr[
'G'] =
'112113';
417 $chr[
'H'] =
'112212';
418 $chr[
'I'] =
'112311';
419 $chr[
'J'] =
'122112';
420 $chr[
'K'] =
'132111';
421 $chr[
'L'] =
'111123';
422 $chr[
'M'] =
'111222';
423 $chr[
'N'] =
'111321';
424 $chr[
'O'] =
'121122';
425 $chr[
'P'] =
'131121';
426 $chr[
'Q'] =
'212112';
427 $chr[
'R'] =
'212211';
428 $chr[
'S'] =
'211122';
429 $chr[
'T'] =
'211221';
430 $chr[
'U'] =
'221121';
431 $chr[
'V'] =
'222111';
432 $chr[
'W'] =
'112122';
433 $chr[
'X'] =
'112221';
434 $chr[
'Y'] =
'122121';
435 $chr[
'Z'] =
'123111';
436 $chr[
'-'] =
'121131';
437 $chr[
'.'] =
'311112';
438 $chr[
' '] =
'311211';
439 $chr[
'$'] =
'321111';
440 $chr[
'/'] =
'112131';
441 $chr[
'+'] =
'113121';
442 $chr[
'%'] =
'211131';
443 $chr[128] =
'121221';
444 $chr[129] =
'311121';
445 $chr[130] =
'122211';
446 $chr[131] =
'312111';
447 $chr[
'*'] =
'111141';
448 $code = strtoupper($code);
450 chr(0) => chr(131).
'U', chr(1) => chr(128).
'A', chr(2) => chr(128).
'B', chr(3) => chr(128).
'C',
451 chr(4) => chr(128).
'D', chr(5) => chr(128).
'E', chr(6) => chr(128).
'F', chr(7) => chr(128).
'G',
452 chr(8) => chr(128).
'H', chr(9) => chr(128).
'I', chr(10) => chr(128).
'J', chr(11) =>
'£K',
453 chr(12) => chr(128).
'L', chr(13) => chr(128).
'M', chr(14) => chr(128).
'N', chr(15) => chr(128).
'O',
454 chr(16) => chr(128).
'P', chr(17) => chr(128).
'Q', chr(18) => chr(128).
'R', chr(19) => chr(128).
'S',
455 chr(20) => chr(128).
'T', chr(21) => chr(128).
'U', chr(22) => chr(128).
'V', chr(23) => chr(128).
'W',
456 chr(24) => chr(128).
'X', chr(25) => chr(128).
'Y', chr(26) => chr(128).
'Z', chr(27) => chr(131).
'A',
457 chr(28) => chr(131).
'B', chr(29) => chr(131).
'C', chr(30) => chr(131).
'D', chr(31) => chr(131).
'E',
458 chr(32) =>
' ', chr(33) => chr(129).
'A', chr(34) => chr(129).
'B', chr(35) => chr(129).
'C',
459 chr(36) => chr(129).
'D', chr(37) => chr(129).
'E', chr(38) => chr(129).
'F', chr(39) => chr(129).
'G',
460 chr(40) => chr(129).
'H', chr(41) => chr(129).
'I', chr(42) => chr(129).
'J', chr(43) => chr(129).
'K',
461 chr(44) => chr(129).
'L', chr(45) =>
'-', chr(46) =>
'.', chr(47) => chr(129).
'O',
462 chr(48) =>
'0', chr(49) =>
'1', chr(50) =>
'2', chr(51) =>
'3',
463 chr(52) =>
'4', chr(53) =>
'5', chr(54) =>
'6', chr(55) =>
'7',
464 chr(56) =>
'8', chr(57) =>
'9', chr(58) => chr(129).
'Z', chr(59) => chr(131).
'F',
465 chr(60) => chr(131).
'G', chr(61) => chr(131).
'H', chr(62) => chr(131).
'I', chr(63) => chr(131).
'J',
466 chr(64) => chr(131).
'V', chr(65) =>
'A', chr(66) =>
'B', chr(67) =>
'C',
467 chr(68) =>
'D', chr(69) =>
'E', chr(70) =>
'F', chr(71) =>
'G',
468 chr(72) =>
'H', chr(73) =>
'I', chr(74) =>
'J', chr(75) =>
'K',
469 chr(76) =>
'L', chr(77) =>
'M', chr(78) =>
'N', chr(79) =>
'O',
470 chr(80) =>
'P', chr(81) =>
'Q', chr(82) =>
'R', chr(83) =>
'S',
471 chr(84) =>
'T', chr(85) =>
'U', chr(86) =>
'V', chr(87) =>
'W',
472 chr(88) =>
'X', chr(89) =>
'Y', chr(90) =>
'Z', chr(91) => chr(131).
'K',
473 chr(92) => chr(131).
'L', chr(93) => chr(131).
'M', chr(94) => chr(131).
'N', chr(95) => chr(131).
'O',
474 chr(96) => chr(131).
'W', chr(97) => chr(130).
'A', chr(98) => chr(130).
'B', chr(99) => chr(130).
'C',
475 chr(100) => chr(130).
'D', chr(101) => chr(130).
'E', chr(102) => chr(130).
'F', chr(103) => chr(130).
'G',
476 chr(104) => chr(130).
'H', chr(105) => chr(130).
'I', chr(106) => chr(130).
'J', chr(107) => chr(130).
'K',
477 chr(108) => chr(130).
'L', chr(109) => chr(130).
'M', chr(110) => chr(130).
'N', chr(111) => chr(130).
'O',
478 chr(112) => chr(130).
'P', chr(113) => chr(130).
'Q', chr(114) => chr(130).
'R', chr(115) => chr(130).
'S',
479 chr(116) => chr(130).
'T', chr(117) => chr(130).
'U', chr(118) => chr(130).
'V', chr(119) => chr(130).
'W',
480 chr(120) => chr(130).
'X', chr(121) => chr(130).
'Y', chr(122) => chr(130).
'Z', chr(123) => chr(131).
'P',
481 chr(124) => chr(131).
'Q', chr(125) => chr(131).
'R', chr(126) => chr(131).
'S', chr(127) => chr(131).
'T');
483 $clen = strlen($code);
484 for ($i = 0 ; $i < $clen; ++$i) {
485 if (ord($code{$i}) > 127) {
488 $code_ext .= $encode[$code{$i}];
493 $code =
'*'.$code.
'*';
494 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
496 $clen = strlen($code);
497 for ($i = 0; $i < $clen; ++$i) {
499 if(!isset($chr[$char])) {
503 for ($j = 0; $j < 6; ++$j) {
509 $w = $chr[$char]{$j};
510 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
511 $bararray[
'maxw'] += $w;
515 $bararray[
'bcode'][$k] = array(
't' =>
true,
'w' => 1,
'h' => 1,
'p' => 0);
516 $bararray[
'maxw'] += 1;
529 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
530 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
531 'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
532 'W',
'X',
'Y',
'Z',
'-',
'.',
' ',
'$',
'/',
'+',
'%');
534 $code = strtr($code, chr(128).chr(129).chr(130).chr(131),
'$/+%');
535 $len = strlen($code);
539 for ($i = ($len - 1); $i >= 0; --$i) {
540 $k = array_keys($chars, $code{$i});
541 $check += ($k[0] * $p);
553 for ($i = $len; $i >= 0; --$i) {
554 $k = array_keys($chars, $code{$i});
555 $check += ($k[0] * $p);
573 $len = strlen($code);
575 for ($i = 0; $i < $len; $i+=2) {
579 for ($i = 1; $i < $len; $i+=2) {
599 $chr[
'0'] =
'100100100100';
600 $chr[
'1'] =
'100100100110';
601 $chr[
'2'] =
'100100110100';
602 $chr[
'3'] =
'100100110110';
603 $chr[
'4'] =
'100110100100';
604 $chr[
'5'] =
'100110100110';
605 $chr[
'6'] =
'100110110100';
606 $chr[
'7'] =
'100110110110';
607 $chr[
'8'] =
'110100100100';
608 $chr[
'9'] =
'110100100110';
609 $chr[
'A'] =
'110100110100';
610 $chr[
'B'] =
'110100110110';
611 $chr[
'C'] =
'110110100100';
612 $chr[
'D'] =
'110110100110';
613 $chr[
'E'] =
'110110110100';
614 $chr[
'F'] =
'110110110110';
617 $clen = strlen($code);
620 for ($i = ($clen - 1); $i >= 0; --$i) {
621 $check += (hexdec($code{$i}) * $p);
629 $check = 11 - $check;
634 $clen = strlen($code);
635 for ($i = 0; $i < $clen; ++$i) {
637 if (!isset($chr[$digit])) {
641 $seq .= $chr[$digit];
644 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
658 $chr[
'0'] =
'10101110111010';
659 $chr[
'1'] =
'11101010101110';
660 $chr[
'2'] =
'10111010101110';
661 $chr[
'3'] =
'11101110101010';
662 $chr[
'4'] =
'10101110101110';
663 $chr[
'5'] =
'11101011101010';
664 $chr[
'6'] =
'10111011101010';
665 $chr[
'7'] =
'10101011101110';
666 $chr[
'8'] =
'10101110111010';
667 $chr[
'9'] =
'10111010111010';
672 if((strlen($code) % 2) != 0) {
677 $clen = strlen($code);
678 for ($i = 0; $i < $clen; ++$i) {
680 if (!isset($chr[$digit])) {
684 $seq .= $chr[$digit];
687 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
702 for ($i = 0; $i < $len; ++$i) {
704 if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
705 if ($seq{$i} ==
'1') {
710 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
711 $bararray[
'maxw'] += $w;
745 if((strlen($code) % 2) != 0) {
750 $code =
'AA'.strtolower($code).
'ZA';
752 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
754 $clen = strlen($code);
755 for ($i = 0; $i < $clen; $i = ($i + 2)) {
756 $char_bar = $code{$i};
757 $char_space = $code{$i+1};
758 if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) {
764 $chrlen = strlen($chr[$char_bar]);
765 for ($s = 0; $s < $chrlen; $s++){
766 $seq .= $chr[$char_bar]{$s} . $chr[$char_space]{$s};
768 $seqlen = strlen($seq);
769 for ($j = 0; $j < $seqlen; ++$j) {
776 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
777 $bararray[
'maxw'] += $w;
904 switch(strtoupper(
$type)) {
907 $keys =
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
908 for ($i = 0; $i < 32; ++$i) {
915 $keys =
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127);
921 if ((strlen($code) % 2) != 0) {
925 for ($i = 0; $i <= 99; ++$i) {
929 $hclen = (strlen($code) / 2);
930 for ($i = 0; $i < $hclen; ++$i) {
931 $new_code .= chr(intval($code{(2 * $i)}.$code{(2 * $i + 1)}));
942 $clen = strlen($code);
943 for ($i = 0; $i < $clen; ++$i) {
944 $sum += (strpos($keys, $code{$i}) * ($i+1));
946 $check = ($sum % 103);
948 $code = chr($startid).$code.chr($check).chr(106).chr(107);
949 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
951 $len = strlen($code);
952 for ($i = 0; $i < $len; ++$i) {
953 $ck = strpos($keys, $code{$i});
954 if (($i == 0) OR ($i > ($len-4))) {
955 $char_num = ord($code{$i});
956 $seq = $chr[$char_num];
957 } elseif(($ck >= 0) AND isset($chr[$ck])) {
963 for ($j = 0; $j < 6; ++$j) {
970 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
971 $bararray[
'maxw'] += $w;
994 $data_len = $len - 1;
996 $code = str_pad($code, $data_len,
'0', STR_PAD_LEFT);
997 $code_len = strlen($code);
1000 for ($i = 1; $i < $data_len; $i+=2) {
1001 $sum_a += $code{$i};
1007 for ($i = 0; $i < $data_len; $i+=2) {
1008 $sum_b += ($code{$i});
1013 $r = ($sum_a + $sum_b) % 10;
1017 if ($code_len == $data_len) {
1020 } elseif ($r !== intval($code{$data_len})) {
1031 $tmp = substr($code, 4, 3);
1032 if (($tmp ==
'000') OR ($tmp ==
'100') OR ($tmp ==
'200')) {
1034 $upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1);
1036 $tmp = substr($code, 5, 2);
1039 $upce_code = substr($code, 2, 3).substr($code, 10, 2).
'3';
1041 $tmp = substr($code, 6, 1);
1044 $upce_code = substr($code, 2, 4).substr($code, 11, 1).
'4';
1047 $upce_code = substr($code, 2, 5).substr($code, 11, 1);
1089 '0'=>array(
'A',
'A',
'A',
'A',
'A',
'A'),
1090 '1'=>array(
'A',
'A',
'B',
'A',
'B',
'B'),
1091 '2'=>array(
'A',
'A',
'B',
'B',
'A',
'B'),
1092 '3'=>array(
'A',
'A',
'B',
'B',
'B',
'A'),
1093 '4'=>array(
'A',
'B',
'A',
'A',
'B',
'B'),
1094 '5'=>array(
'A',
'B',
'B',
'A',
'A',
'B'),
1095 '6'=>array(
'A',
'B',
'B',
'B',
'A',
'A'),
1096 '7'=>array(
'A',
'B',
'A',
'B',
'A',
'B'),
1097 '8'=>array(
'A',
'B',
'A',
'B',
'B',
'A'),
1098 '9'=>array(
'A',
'B',
'B',
'A',
'B',
'A')
1100 $upce_parities = array();
1101 $upce_parities[0] = array(
1102 '0'=>array(
'B',
'B',
'B',
'A',
'A',
'A'),
1103 '1'=>array(
'B',
'B',
'A',
'B',
'A',
'A'),
1104 '2'=>array(
'B',
'B',
'A',
'A',
'B',
'A'),
1105 '3'=>array(
'B',
'B',
'A',
'A',
'A',
'B'),
1106 '4'=>array(
'B',
'A',
'B',
'B',
'A',
'A'),
1107 '5'=>array(
'B',
'A',
'A',
'B',
'B',
'A'),
1108 '6'=>array(
'B',
'A',
'A',
'A',
'B',
'B'),
1109 '7'=>array(
'B',
'A',
'B',
'A',
'B',
'A'),
1110 '8'=>array(
'B',
'A',
'B',
'A',
'A',
'B'),
1111 '9'=>array(
'B',
'A',
'A',
'B',
'A',
'B')
1113 $upce_parities[1] = array(
1114 '0'=>array(
'A',
'A',
'A',
'B',
'B',
'B'),
1115 '1'=>array(
'A',
'A',
'B',
'A',
'B',
'B'),
1116 '2'=>array(
'A',
'A',
'B',
'B',
'A',
'B'),
1117 '3'=>array(
'A',
'A',
'B',
'B',
'B',
'A'),
1118 '4'=>array(
'A',
'B',
'A',
'A',
'B',
'B'),
1119 '5'=>array(
'A',
'B',
'B',
'A',
'A',
'B'),
1120 '6'=>array(
'A',
'B',
'B',
'B',
'A',
'A'),
1121 '7'=>array(
'A',
'B',
'A',
'B',
'A',
'B'),
1122 '8'=>array(
'A',
'B',
'A',
'B',
'B',
'A'),
1123 '9'=>array(
'A',
'B',
'B',
'A',
'B',
'A')
1128 $bararray = array(
'code' => $upce_code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1129 $p = $upce_parities[$code{1}][$r];
1130 for ($i = 0; $i < 6; ++$i) {
1131 $seq .= $codes[$p[$i]][$upce_code{$i}];
1135 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1136 $half_len = ceil($len / 2);
1138 for ($i = 0; $i < $half_len; ++$i) {
1139 $seq .= $codes[
'A'][$code{$i}];
1142 $p = $parities[$code{0}];
1143 for ($i = 1; $i < $half_len; ++$i) {
1144 $seq .= $codes[$p[$i-1]][$code{$i}];
1148 for ($i = $half_len; $i < $len; ++$i) {
1149 $seq .= $codes[
'C'][$code{$i}];
1153 $clen = strlen($seq);
1155 for ($i = 0; $i < $clen; ++$i) {
1157 if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
1158 if ($seq{$i} ==
'1') {
1163 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
1164 $bararray[
'maxw'] += $w;
1183 $code = str_pad($code, $len,
'0', STR_PAD_LEFT);
1187 } elseif ($len == 5) {
1188 $r = (3 * ($code{0} + $code{2} + $code{4})) + (9 * ($code{1} + $code{3}));
1218 $parities = array();
1219 $parities[2] = array(
1220 '0'=>array(
'A',
'A'),
1221 '1'=>array(
'A',
'B'),
1222 '2'=>array(
'B',
'A'),
1225 $parities[5] = array(
1226 '0'=>array(
'B',
'B',
'A',
'A',
'A'),
1227 '1'=>array(
'B',
'A',
'B',
'A',
'A'),
1228 '2'=>array(
'B',
'A',
'A',
'B',
'A'),
1229 '3'=>array(
'B',
'A',
'A',
'A',
'B'),
1230 '4'=>array(
'A',
'B',
'B',
'A',
'A'),
1231 '5'=>array(
'A',
'A',
'B',
'B',
'A'),
1232 '6'=>array(
'A',
'A',
'A',
'B',
'B'),
1233 '7'=>array(
'A',
'B',
'A',
'B',
'A'),
1234 '8'=>array(
'A',
'B',
'A',
'A',
'B'),
1235 '9'=>array(
'A',
'A',
'B',
'A',
'B')
1237 $p = $parities[$len][$r];
1239 $seq .= $codes[$p[0]][$code{0}];
1240 for ($i = 1; $i < $len; ++$i) {
1242 $seq .= $codes[$p[$i]][$code{$i}];
1244 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1260 0 => Array(1,1,2,2,2),
1261 1 => Array(2,2,2,1,1),
1262 2 => Array(2,2,1,2,1),
1263 3 => Array(2,2,1,1,2),
1264 4 => Array(2,1,2,2,1),
1265 5 => Array(2,1,2,1,2),
1266 6 => Array(2,1,1,2,2),
1267 7 => Array(1,2,2,2,1),
1268 8 => Array(1,2,2,1,2),
1269 9 => Array(1,2,1,2,2)
1273 0 => Array(2,2,1,1,1),
1274 1 => Array(1,1,1,2,2),
1275 2 => Array(1,1,2,1,2),
1276 3 => Array(1,1,2,2,1),
1277 4 => Array(1,2,1,1,2),
1278 5 => Array(1,2,1,2,1),
1279 6 => Array(1,2,2,1,1),
1280 7 => Array(2,1,1,1,2),
1281 8 => Array(2,1,1,2,1),
1282 9 => Array(2,1,2,1,1)
1285 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 2,
'bcode' => array());
1287 $code = str_replace(
'-',
'', $code);
1288 $code = str_replace(
' ',
'', $code);
1289 $len = strlen($code);
1292 for ($i = 0; $i < $len; ++$i) {
1293 $sum += intval($code{$i});
1295 $chkd = ($sum % 10);
1297 $chkd = (10 - $chkd);
1300 $len = strlen($code);
1302 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => 2,
'p' => 0);
1303 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1304 $bararray[
'maxw'] += 2;
1305 for ($i = 0; $i < $len; ++$i) {
1306 for ($j = 0; $j < 5; ++$j) {
1307 $h = $barlen[$code{$i}][$j];
1309 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => $h,
'p' => $p);
1310 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1311 $bararray[
'maxw'] += 2;
1315 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => 2,
'p' => 0);
1316 $bararray[
'maxw'] += 1;
1337 '0' => array(3,3,2,2),
1338 '1' => array(3,4,1,2),
1339 '2' => array(3,4,2,1),
1340 '3' => array(4,3,1,2),
1341 '4' => array(4,3,2,1),
1342 '5' => array(4,4,1,1),
1343 '6' => array(3,1,4,2),
1344 '7' => array(3,2,3,2),
1345 '8' => array(3,2,4,1),
1346 '9' => array(4,1,3,2),
1347 'A' => array(4,1,4,1),
1348 'B' => array(4,2,3,1),
1349 'C' => array(3,1,2,4),
1350 'D' => array(3,2,1,4),
1351 'E' => array(3,2,2,3),
1352 'F' => array(4,1,1,4),
1353 'G' => array(4,1,2,3),
1354 'H' => array(4,2,1,3),
1355 'I' => array(1,3,4,2),
1356 'J' => array(1,4,3,2),
1357 'K' => array(1,4,4,1),
1358 'L' => array(2,3,3,2),
1359 'M' => array(2,3,4,1),
1360 'N' => array(2,4,3,1),
1361 'O' => array(1,3,2,4),
1362 'P' => array(1,4,1,4),
1363 'Q' => array(1,4,2,3),
1364 'R' => array(2,3,1,4),
1365 'S' => array(2,3,2,3),
1366 'T' => array(2,4,1,3),
1367 'U' => array(1,1,4,4),
1368 'V' => array(1,2,3,4),
1369 'W' => array(1,2,4,3),
1370 'X' => array(2,1,3,4),
1371 'Y' => array(2,1,4,3),
1372 'Z' => array(2,2,3,3)
1374 $code = strtoupper($code);
1375 $len = strlen($code);
1376 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 3,
'bcode' => array());
1379 $checktable = array(
1419 for ($i = 0; $i < $len; ++$i) {
1420 $row += $checktable[$code{$i}][0];
1421 $col += $checktable[$code{$i}][1];
1425 $chk = array_keys($checktable, array(
$row,$col));
1432 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => 2,
'p' => 0);
1433 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1434 $bararray[
'maxw'] += 2;
1436 for ($i = 0; $i < $len; ++$i) {
1437 for ($j = 0; $j < 4; ++$j) {
1438 switch ($barmode[$code{$i}][$j]) {
1460 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => $h,
'p' => $p);
1461 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1462 $bararray[
'maxw'] += 2;
1467 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => 3,
'p' => 0);
1468 $bararray[
'maxw'] += 1;
1503 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1507 $code =
'A'.strtoupper($code).
'A';
1508 $len = strlen($code);
1509 for ($i = 0; $i < $len; ++$i) {
1510 if (!isset($chr[$code{$i}])) {
1513 $seq = $chr[$code{$i}];
1514 for ($j = 0; $j < 8; ++$j) {
1515 if (($j % 2) == 0) {
1521 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
1522 $bararray[
'maxw'] += $w;
1552 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1556 $len = strlen($code);
1560 for ($i = ($len - 1); $i >= 0; --$i) {
1562 if ($digit ==
'-') {
1565 $dval = intval($digit);
1567 $check += ($dval * $p);
1582 for ($i = $len; $i >= 0; --$i) {
1584 if ($digit ==
'-') {
1587 $dval = intval($digit);
1589 $check += ($dval * $p);
1599 $code =
'S'.$code.
'S';
1601 for ($i = 0; $i < $len; ++$i) {
1602 if (!isset($chr[$code{$i}])) {
1605 $seq = $chr[$code{$i}];
1606 for ($j = 0; $j < 6; ++$j) {
1607 if (($j % 2) == 0) {
1613 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
1614 $bararray[
'maxw'] += $w;
1630 $code = intval($code);
1632 if (($code % 2) == 0) {
1641 $seq = substr($seq, 0, -2);
1642 $seq = strrev($seq);
1643 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1656 $code = intval($code);
1658 switch ($code % 3) {
1661 $code = ($code - 3) / 3;
1666 $code = ($code - 1) / 3;
1671 $code = ($code - 2) / 3;
1675 }
while($code != 0);
1676 $seq = strrev($seq);
1678 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 2,
'bcode' => array());
1679 $len = strlen($seq);
1680 for ($i = 0; $i < $len; ++$i) {
1698 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => $h,
'p' => $p);
1699 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1700 $bararray[
'maxw'] += 2;
1702 unset($bararray[
'bcode'][($k - 1)]);
1703 --$bararray[
'maxw'];
1718 $asc_chr = array(4,0,2,6,3,5,1,9,8,7,1,2,0,6,4,8,2,9,5,3,0,1,3,7,4,6,8,9,2,0,5,1,9,4,3,8,6,7,1,2,4,3,9,5,7,8,3,0,2,1,4,0,9,1,7,0,2,4,6,3,7,1,9,5,8);
1719 $dsc_chr = array(7,1,9,5,8,0,2,4,6,3,5,8,9,7,3,0,6,1,7,4,6,8,9,2,5,1,7,5,4,3,8,7,6,0,2,5,4,9,3,0,1,6,8,2,0,4,5,9,6,7,5,2,6,3,8,5,1,9,8,7,4,0,2,6,3);
1720 $asc_pos = array(3,0,8,11,1,12,8,11,10,6,4,12,2,7,9,6,7,9,2,8,4,0,12,7,10,9,0,7,10,5,7,9,6,8,2,12,1,4,2,0,1,5,4,6,12,1,0,9,4,7,5,10,2,6,9,11,2,12,6,7,5,11,0,3,2);
1721 $dsc_pos = array(2,10,12,5,9,1,5,4,3,9,11,5,10,1,6,3,4,1,10,0,2,11,8,6,1,12,3,8,6,4,4,11,0,6,1,9,11,5,3,7,3,10,7,11,8,2,10,3,5,8,0,3,12,11,8,4,5,1,3,0,7,12,9,8,10);
1722 $code_arr = explode(
'-', $code);
1723 $tracking_number = $code_arr[0];
1724 if (isset($code_arr[1])) {
1725 $routing_code = $code_arr[1];
1730 switch (strlen($routing_code)) {
1736 $binary_code = bcadd($routing_code,
'1');
1740 $binary_code = bcadd($routing_code,
'100001');
1744 $binary_code = bcadd($routing_code,
'1000100001');
1752 $binary_code = bcmul($binary_code, 10);
1753 $binary_code = bcadd($binary_code, $tracking_number{0});
1754 $binary_code = bcmul($binary_code, 5);
1755 $binary_code = bcadd($binary_code, $tracking_number{1});
1756 $binary_code .= substr($tracking_number, 2, 18);
1758 $binary_code = $this->
dec_to_hex($binary_code);
1760 $binary_code = str_pad($binary_code, 26,
'0', STR_PAD_LEFT);
1762 $binary_code_arr = chunk_split($binary_code, 2,
"\r");
1763 $binary_code_arr = substr($binary_code_arr, 0, -1);
1764 $binary_code_arr = explode(
"\r", $binary_code_arr);
1768 $first_byte = sprintf(
'%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2));
1769 $binary_code_102bit = $first_byte.substr($binary_code, 2);
1771 $codewords = array();
1773 $codewords[0] = bcmod(
$data, 636) * 2;
1775 for ($i = 1; $i < 9; ++$i) {
1776 $codewords[$i] = bcmod(
$data, 1365);
1779 $codewords[9] =
$data;
1780 if (($fcs >> 10) == 1) {
1781 $codewords[9] += 659;
1787 $characters = array();
1789 foreach($codewords as $k => $val) {
1791 $chrcode = $table5of13[$val];
1793 $chrcode = $table2of13[($val - 1287)];
1795 if (($fcs & $bitmask) > 0) {
1797 $chrcode = ((~$chrcode) & 8191);
1799 $characters[] = $chrcode;
1802 $characters = array_reverse($characters);
1805 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 3,
'bcode' => array());
1806 for ($i = 0; $i < 65; ++$i) {
1807 $asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0);
1808 $dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0);
1809 if ($asc AND $dsc) {
1826 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => $h,
'p' => $p);
1827 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1828 $bararray[
'maxw'] += 2;
1830 unset($bararray[
'bcode'][($k - 1)]);
1831 --$bararray[
'maxw'];
1847 while($number > 0) {
1849 array_push($hex,
'0');
1851 array_push($hex, strtoupper(dechex(bcmod($number,
'16'))));
1852 $number = bcdiv($number,
'16', 0);
1855 $hex = array_reverse($hex);
1856 return implode($hex);
1868 $len = strlen($hex);
1870 $dec = bcadd($dec, bcmul(hexdec($hex{
$pos}), $bitval));
1871 $bitval = bcmul($bitval, 16);
1886 $data = hexdec($code_arr[0]) << 5;
1887 for ($bit = 2; $bit < 8; ++$bit) {
1888 if (($fcs ^
$data) & 0x400) {
1889 $fcs = ($fcs << 1) ^ $genpoly;
1897 for ($byte = 1; $byte < 13; ++$byte) {
1898 $data = hexdec($code_arr[$byte]) << 3;
1899 for ($bit = 0; $bit < 8; ++$bit) {
1900 if (($fcs ^
$data) & 0x400) {
1901 $fcs = ($fcs << 1) ^ $genpoly;
1920 for ($i = 0; $i < 16; ++$i) {
1939 for ($count = 0; $count < 8192; ++$count) {
1941 for ($bit_index = 0; $bit_index < 13; ++$bit_index) {
1942 $bit_count += intval(($count & (1 << $bit_index)) != 0);
1945 if ($bit_count == $n) {
1948 if ($reverse >= $count) {
1951 if ($reverse == $count) {
1952 $table[$lui] = $count;
1955 $table[$lli] = $count;
1957 $table[$lli] = $reverse;