103 switch (strtoupper(
$type)) {
221 $this->barcode_array =
false;
224 $this->barcode_array = $arrcode;
236 $chr[
'0'] =
'111221211';
237 $chr[
'1'] =
'211211112';
238 $chr[
'2'] =
'112211112';
239 $chr[
'3'] =
'212211111';
240 $chr[
'4'] =
'111221112';
241 $chr[
'5'] =
'211221111';
242 $chr[
'6'] =
'112221111';
243 $chr[
'7'] =
'111211212';
244 $chr[
'8'] =
'211211211';
245 $chr[
'9'] =
'112211211';
246 $chr[
'A'] =
'211112112';
247 $chr[
'B'] =
'112112112';
248 $chr[
'C'] =
'212112111';
249 $chr[
'D'] =
'111122112';
250 $chr[
'E'] =
'211122111';
251 $chr[
'F'] =
'112122111';
252 $chr[
'G'] =
'111112212';
253 $chr[
'H'] =
'211112211';
254 $chr[
'I'] =
'112112211';
255 $chr[
'J'] =
'111122211';
256 $chr[
'K'] =
'211111122';
257 $chr[
'L'] =
'112111122';
258 $chr[
'M'] =
'212111121';
259 $chr[
'N'] =
'111121122';
260 $chr[
'O'] =
'211121121';
261 $chr[
'P'] =
'112121121';
262 $chr[
'Q'] =
'111111222';
263 $chr[
'R'] =
'211111221';
264 $chr[
'S'] =
'112111221';
265 $chr[
'T'] =
'111121221';
266 $chr[
'U'] =
'221111112';
267 $chr[
'V'] =
'122111112';
268 $chr[
'W'] =
'222111111';
269 $chr[
'X'] =
'121121112';
270 $chr[
'Y'] =
'221121111';
271 $chr[
'Z'] =
'122121111';
272 $chr[
'-'] =
'121111212';
273 $chr[
'.'] =
'221111211';
274 $chr[
' '] =
'122111211';
275 $chr[
'$'] =
'121212111';
276 $chr[
'/'] =
'121211121';
277 $chr[
'+'] =
'121112121';
278 $chr[
'%'] =
'111212121';
279 $chr[
'*'] =
'121121211';
281 $code = strtoupper($code);
286 if ($code ===
false) {
294 $code =
'*'.$code.
'*';
296 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
298 $clen = strlen($code);
299 for ($i = 0; $i < $clen; ++$i) {
301 if(!isset($chr[$char])) {
305 for ($j = 0; $j < 9; ++$j) {
311 $w = $chr[$char]{$j};
312 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
313 $bararray[
'maxw'] += $w;
316 $bararray[
'bcode'][$k] = array(
't' =>
false,
'w' => 1,
'h' => 1,
'p' => 0);
317 $bararray[
'maxw'] += 1;
331 chr(0) =>
'%U', chr(1) =>
'$A', chr(2) =>
'$B', chr(3) =>
'$C',
332 chr(4) =>
'$D', chr(5) =>
'$E', chr(6) =>
'$F', chr(7) =>
'$G',
333 chr(8) =>
'$H', chr(9) =>
'$I', chr(10) =>
'$J', chr(11) =>
'£K',
334 chr(12) =>
'$L', chr(13) =>
'$M', chr(14) =>
'$N', chr(15) =>
'$O',
335 chr(16) =>
'$P', chr(17) =>
'$Q', chr(18) =>
'$R', chr(19) =>
'$S',
336 chr(20) =>
'$T', chr(21) =>
'$U', chr(22) =>
'$V', chr(23) =>
'$W',
337 chr(24) =>
'$X', chr(25) =>
'$Y', chr(26) =>
'$Z', chr(27) =>
'%A',
338 chr(28) =>
'%B', chr(29) =>
'%C', chr(30) =>
'%D', chr(31) =>
'%E',
339 chr(32) =>
' ', chr(33) =>
'/A', chr(34) =>
'/B', chr(35) =>
'/C',
340 chr(36) =>
'/D', chr(37) =>
'/E', chr(38) =>
'/F', chr(39) =>
'/G',
341 chr(40) =>
'/H', chr(41) =>
'/I', chr(42) =>
'/J', chr(43) =>
'/K',
342 chr(44) =>
'/L', chr(45) =>
'-', chr(46) =>
'.', chr(47) =>
'/O',
343 chr(48) =>
'0', chr(49) =>
'1', chr(50) =>
'2', chr(51) =>
'3',
344 chr(52) =>
'4', chr(53) =>
'5', chr(54) =>
'6', chr(55) =>
'7',
345 chr(56) =>
'8', chr(57) =>
'9', chr(58) =>
'/Z', chr(59) =>
'%F',
346 chr(60) =>
'%G', chr(61) =>
'%H', chr(62) =>
'%I', chr(63) =>
'%J',
347 chr(64) =>
'%V', chr(65) =>
'A', chr(66) =>
'B', chr(67) =>
'C',
348 chr(68) =>
'D', chr(69) =>
'E', chr(70) =>
'F', chr(71) =>
'G',
349 chr(72) =>
'H', chr(73) =>
'I', chr(74) =>
'J', chr(75) =>
'K',
350 chr(76) =>
'L', chr(77) =>
'M', chr(78) =>
'N', chr(79) =>
'O',
351 chr(80) =>
'P', chr(81) =>
'Q', chr(82) =>
'R', chr(83) =>
'S',
352 chr(84) =>
'T', chr(85) =>
'U', chr(86) =>
'V', chr(87) =>
'W',
353 chr(88) =>
'X', chr(89) =>
'Y', chr(90) =>
'Z', chr(91) =>
'%K',
354 chr(92) =>
'%L', chr(93) =>
'%M', chr(94) =>
'%N', chr(95) =>
'%O',
355 chr(96) =>
'%W', chr(97) =>
'+A', chr(98) =>
'+B', chr(99) =>
'+C',
356 chr(100) =>
'+D', chr(101) =>
'+E', chr(102) =>
'+F', chr(103) =>
'+G',
357 chr(104) =>
'+H', chr(105) =>
'+I', chr(106) =>
'+J', chr(107) =>
'+K',
358 chr(108) =>
'+L', chr(109) =>
'+M', chr(110) =>
'+N', chr(111) =>
'+O',
359 chr(112) =>
'+P', chr(113) =>
'+Q', chr(114) =>
'+R', chr(115) =>
'+S',
360 chr(116) =>
'+T', chr(117) =>
'+U', chr(118) =>
'+V', chr(119) =>
'+W',
361 chr(120) =>
'+X', chr(121) =>
'+Y', chr(122) =>
'+Z', chr(123) =>
'%P',
362 chr(124) =>
'%Q', chr(125) =>
'%R', chr(126) =>
'%S', chr(127) =>
'%T');
364 $clen = strlen($code);
365 for ($i = 0 ; $i < $clen; ++$i) {
366 if (ord($code{$i}) > 127) {
369 $code_ext .= $encode[$code{$i}];
382 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
383 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
384 'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
385 'W',
'X',
'Y',
'Z',
'-',
'.',
' ',
'$',
'/',
'+',
'%');
387 $clen = strlen($code);
388 for ($i = 0 ; $i < $clen; ++$i) {
389 $k = array_keys($chars, $code{$i});
405 $chr[
'0'] =
'131112';
406 $chr[
'1'] =
'111213';
407 $chr[
'2'] =
'111312';
408 $chr[
'3'] =
'111411';
409 $chr[
'4'] =
'121113';
410 $chr[
'5'] =
'121212';
411 $chr[
'6'] =
'121311';
412 $chr[
'7'] =
'111114';
413 $chr[
'8'] =
'131211';
414 $chr[
'9'] =
'141111';
415 $chr[
'A'] =
'211113';
416 $chr[
'B'] =
'211212';
417 $chr[
'C'] =
'211311';
418 $chr[
'D'] =
'221112';
419 $chr[
'E'] =
'221211';
420 $chr[
'F'] =
'231111';
421 $chr[
'G'] =
'112113';
422 $chr[
'H'] =
'112212';
423 $chr[
'I'] =
'112311';
424 $chr[
'J'] =
'122112';
425 $chr[
'K'] =
'132111';
426 $chr[
'L'] =
'111123';
427 $chr[
'M'] =
'111222';
428 $chr[
'N'] =
'111321';
429 $chr[
'O'] =
'121122';
430 $chr[
'P'] =
'131121';
431 $chr[
'Q'] =
'212112';
432 $chr[
'R'] =
'212211';
433 $chr[
'S'] =
'211122';
434 $chr[
'T'] =
'211221';
435 $chr[
'U'] =
'221121';
436 $chr[
'V'] =
'222111';
437 $chr[
'W'] =
'112122';
438 $chr[
'X'] =
'112221';
439 $chr[
'Y'] =
'122121';
440 $chr[
'Z'] =
'123111';
441 $chr[
'-'] =
'121131';
442 $chr[
'.'] =
'311112';
443 $chr[
' '] =
'311211';
444 $chr[
'$'] =
'321111';
445 $chr[
'/'] =
'112131';
446 $chr[
'+'] =
'113121';
447 $chr[
'%'] =
'211131';
448 $chr[128] =
'121221';
449 $chr[129] =
'311121';
450 $chr[130] =
'122211';
451 $chr[131] =
'312111';
452 $chr[
'*'] =
'111141';
453 $code = strtoupper($code);
455 chr(0) => chr(131).
'U', chr(1) => chr(128).
'A', chr(2) => chr(128).
'B', chr(3) => chr(128).
'C',
456 chr(4) => chr(128).
'D', chr(5) => chr(128).
'E', chr(6) => chr(128).
'F', chr(7) => chr(128).
'G',
457 chr(8) => chr(128).
'H', chr(9) => chr(128).
'I', chr(10) => chr(128).
'J', chr(11) =>
'£K',
458 chr(12) => chr(128).
'L', chr(13) => chr(128).
'M', chr(14) => chr(128).
'N', chr(15) => chr(128).
'O',
459 chr(16) => chr(128).
'P', chr(17) => chr(128).
'Q', chr(18) => chr(128).
'R', chr(19) => chr(128).
'S',
460 chr(20) => chr(128).
'T', chr(21) => chr(128).
'U', chr(22) => chr(128).
'V', chr(23) => chr(128).
'W',
461 chr(24) => chr(128).
'X', chr(25) => chr(128).
'Y', chr(26) => chr(128).
'Z', chr(27) => chr(131).
'A',
462 chr(28) => chr(131).
'B', chr(29) => chr(131).
'C', chr(30) => chr(131).
'D', chr(31) => chr(131).
'E',
463 chr(32) =>
' ', chr(33) => chr(129).
'A', chr(34) => chr(129).
'B', chr(35) => chr(129).
'C',
464 chr(36) => chr(129).
'D', chr(37) => chr(129).
'E', chr(38) => chr(129).
'F', chr(39) => chr(129).
'G',
465 chr(40) => chr(129).
'H', chr(41) => chr(129).
'I', chr(42) => chr(129).
'J', chr(43) => chr(129).
'K',
466 chr(44) => chr(129).
'L', chr(45) =>
'-', chr(46) =>
'.', chr(47) => chr(129).
'O',
467 chr(48) =>
'0', chr(49) =>
'1', chr(50) =>
'2', chr(51) =>
'3',
468 chr(52) =>
'4', chr(53) =>
'5', chr(54) =>
'6', chr(55) =>
'7',
469 chr(56) =>
'8', chr(57) =>
'9', chr(58) => chr(129).
'Z', chr(59) => chr(131).
'F',
470 chr(60) => chr(131).
'G', chr(61) => chr(131).
'H', chr(62) => chr(131).
'I', chr(63) => chr(131).
'J',
471 chr(64) => chr(131).
'V', chr(65) =>
'A', chr(66) =>
'B', chr(67) =>
'C',
472 chr(68) =>
'D', chr(69) =>
'E', chr(70) =>
'F', chr(71) =>
'G',
473 chr(72) =>
'H', chr(73) =>
'I', chr(74) =>
'J', chr(75) =>
'K',
474 chr(76) =>
'L', chr(77) =>
'M', chr(78) =>
'N', chr(79) =>
'O',
475 chr(80) =>
'P', chr(81) =>
'Q', chr(82) =>
'R', chr(83) =>
'S',
476 chr(84) =>
'T', chr(85) =>
'U', chr(86) =>
'V', chr(87) =>
'W',
477 chr(88) =>
'X', chr(89) =>
'Y', chr(90) =>
'Z', chr(91) => chr(131).
'K',
478 chr(92) => chr(131).
'L', chr(93) => chr(131).
'M', chr(94) => chr(131).
'N', chr(95) => chr(131).
'O',
479 chr(96) => chr(131).
'W', chr(97) => chr(130).
'A', chr(98) => chr(130).
'B', chr(99) => chr(130).
'C',
480 chr(100) => chr(130).
'D', chr(101) => chr(130).
'E', chr(102) => chr(130).
'F', chr(103) => chr(130).
'G',
481 chr(104) => chr(130).
'H', chr(105) => chr(130).
'I', chr(106) => chr(130).
'J', chr(107) => chr(130).
'K',
482 chr(108) => chr(130).
'L', chr(109) => chr(130).
'M', chr(110) => chr(130).
'N', chr(111) => chr(130).
'O',
483 chr(112) => chr(130).
'P', chr(113) => chr(130).
'Q', chr(114) => chr(130).
'R', chr(115) => chr(130).
'S',
484 chr(116) => chr(130).
'T', chr(117) => chr(130).
'U', chr(118) => chr(130).
'V', chr(119) => chr(130).
'W',
485 chr(120) => chr(130).
'X', chr(121) => chr(130).
'Y', chr(122) => chr(130).
'Z', chr(123) => chr(131).
'P',
486 chr(124) => chr(131).
'Q', chr(125) => chr(131).
'R', chr(126) => chr(131).
'S', chr(127) => chr(131).
'T');
488 $clen = strlen($code);
489 for ($i = 0 ; $i < $clen; ++$i) {
490 if (ord($code{$i}) > 127) {
493 $code_ext .= $encode[$code{$i}];
498 $code =
'*'.$code.
'*';
499 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
501 $clen = strlen($code);
502 for ($i = 0; $i < $clen; ++$i) {
504 if(!isset($chr[$char])) {
508 for ($j = 0; $j < 6; ++$j) {
514 $w = $chr[$char]{$j};
515 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
516 $bararray[
'maxw'] += $w;
520 $bararray[
'bcode'][$k] = array(
't' =>
true,
'w' => 1,
'h' => 1,
'p' => 0);
521 $bararray[
'maxw'] += 1;
534 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
535 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
'K',
536 'L',
'M',
'N',
'O',
'P',
'Q',
'R',
'S',
'T',
'U',
'V',
537 'W',
'X',
'Y',
'Z',
'-',
'.',
' ',
'$',
'/',
'+',
'%');
539 $code = strtr($code, chr(128).chr(129).chr(130).chr(131),
'$/+%');
540 $len = strlen($code);
544 for ($i = ($len - 1); $i >= 0; --$i) {
545 $k = array_keys($chars, $code{$i});
546 $check += ($k[0] * $p);
558 for ($i = $len; $i >= 0; --$i) {
559 $k = array_keys($chars, $code{$i});
560 $check += ($k[0] * $p);
578 $len = strlen($code);
580 for ($i = 0; $i < $len; $i+=2) {
584 for ($i = 1; $i < $len; $i+=2) {
604 $chr[
'0'] =
'100100100100';
605 $chr[
'1'] =
'100100100110';
606 $chr[
'2'] =
'100100110100';
607 $chr[
'3'] =
'100100110110';
608 $chr[
'4'] =
'100110100100';
609 $chr[
'5'] =
'100110100110';
610 $chr[
'6'] =
'100110110100';
611 $chr[
'7'] =
'100110110110';
612 $chr[
'8'] =
'110100100100';
613 $chr[
'9'] =
'110100100110';
614 $chr[
'A'] =
'110100110100';
615 $chr[
'B'] =
'110100110110';
616 $chr[
'C'] =
'110110100100';
617 $chr[
'D'] =
'110110100110';
618 $chr[
'E'] =
'110110110100';
619 $chr[
'F'] =
'110110110110';
622 $clen = strlen($code);
625 for ($i = ($clen - 1); $i >= 0; --$i) {
626 $check += (hexdec($code{$i}) * $p);
634 $check = 11 - $check;
639 $clen = strlen($code);
640 for ($i = 0; $i < $clen; ++$i) {
642 if (!isset($chr[$digit])) {
646 $seq .= $chr[$digit];
649 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
663 $chr[
'0'] =
'10101110111010';
664 $chr[
'1'] =
'11101010101110';
665 $chr[
'2'] =
'10111010101110';
666 $chr[
'3'] =
'11101110101010';
667 $chr[
'4'] =
'10101110101110';
668 $chr[
'5'] =
'11101011101010';
669 $chr[
'6'] =
'10111011101010';
670 $chr[
'7'] =
'10101011101110';
671 $chr[
'8'] =
'10101110111010';
672 $chr[
'9'] =
'10111010111010';
677 if((strlen($code) % 2) != 0) {
682 $clen = strlen($code);
683 for ($i = 0; $i < $clen; ++$i) {
685 if (!isset($chr[$digit])) {
689 $seq .= $chr[$digit];
692 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
707 for ($i = 0; $i < $len; ++$i) {
709 if (($i == ($len - 1)) OR (($i < ($len - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
710 if ($seq{$i} ==
'1') {
715 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
716 $bararray[
'maxw'] += $w;
750 if((strlen($code) % 2) != 0) {
755 $code =
'AA'.strtolower($code).
'ZA';
757 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
759 $clen = strlen($code);
760 for ($i = 0; $i < $clen; $i = ($i + 2)) {
761 $char_bar = $code{$i};
762 $char_space = $code{$i+1};
763 if((!isset($chr[$char_bar])) OR (!isset($chr[$char_space]))) {
769 $chrlen = strlen($chr[$char_bar]);
770 for ($s = 0; $s < $chrlen; $s++){
771 $seq .= $chr[$char_bar]{$s} . $chr[$char_space]{$s};
773 $seqlen = strlen($seq);
774 for ($j = 0; $j < $seqlen; ++$j) {
781 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
782 $bararray[
'maxw'] += $w;
909 switch(strtoupper(
$type)) {
912 $keys =
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_';
913 for ($i = 0; $i < 32; ++$i) {
920 $keys =
' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~'.chr(127);
926 if ((strlen($code) % 2) != 0) {
930 for ($i = 0; $i <= 99; ++$i) {
934 $hclen = (strlen($code) / 2);
935 for ($i = 0; $i < $hclen; ++$i) {
936 $new_code .= chr(intval($code{(2 * $i)}.$code{(2 * $i + 1)}));
947 $clen = strlen($code);
948 for ($i = 0; $i < $clen; ++$i) {
949 $sum += (strpos($keys, $code{$i}) * ($i+1));
951 $check = ($sum % 103);
953 $code = chr($startid).$code.chr($check).chr(106).chr(107);
954 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
956 $len = strlen($code);
957 for ($i = 0; $i < $len; ++$i) {
958 $ck = strpos($keys, $code{$i});
959 if (($i == 0) OR ($i > ($len-4))) {
960 $char_num = ord($code{$i});
961 $seq = $chr[$char_num];
962 }
elseif(($ck >= 0) AND isset($chr[$ck])) {
968 for ($j = 0; $j < 6; ++$j) {
975 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
976 $bararray[
'maxw'] += $w;
999 $data_len = $len - 1;
1001 $code = str_pad($code, $data_len,
'0', STR_PAD_LEFT);
1002 $code_len = strlen($code);
1005 for ($i = 1; $i < $data_len; $i+=2) {
1006 $sum_a += $code{$i};
1012 for ($i = 0; $i < $data_len; $i+=2) {
1013 $sum_b += ($code{$i});
1018 $r = ($sum_a + $sum_b) % 10;
1022 if ($code_len == $data_len) {
1025 }
elseif ($r !== intval($code{$data_len})) {
1036 $tmp = substr($code, 4, 3);
1037 if (($tmp ==
'000') OR ($tmp ==
'100') OR ($tmp ==
'200')) {
1039 $upce_code = substr($code, 2, 2).substr($code, 9, 3).substr($code, 4, 1);
1041 $tmp = substr($code, 5, 2);
1044 $upce_code = substr($code, 2, 3).substr($code, 10, 2).
'3';
1046 $tmp = substr($code, 6, 1);
1049 $upce_code = substr($code, 2, 4).substr($code, 11, 1).
'4';
1052 $upce_code = substr($code, 2, 5).substr($code, 11, 1);
1094 '0'=>array(
'A',
'A',
'A',
'A',
'A',
'A'),
1095 '1'=>array(
'A',
'A',
'B',
'A',
'B',
'B'),
1096 '2'=>array(
'A',
'A',
'B',
'B',
'A',
'B'),
1097 '3'=>array(
'A',
'A',
'B',
'B',
'B',
'A'),
1098 '4'=>array(
'A',
'B',
'A',
'A',
'B',
'B'),
1099 '5'=>array(
'A',
'B',
'B',
'A',
'A',
'B'),
1100 '6'=>array(
'A',
'B',
'B',
'B',
'A',
'A'),
1101 '7'=>array(
'A',
'B',
'A',
'B',
'A',
'B'),
1102 '8'=>array(
'A',
'B',
'A',
'B',
'B',
'A'),
1103 '9'=>array(
'A',
'B',
'B',
'A',
'B',
'A')
1105 $upce_parities = array();
1106 $upce_parities[0] = array(
1107 '0'=>array(
'B',
'B',
'B',
'A',
'A',
'A'),
1108 '1'=>array(
'B',
'B',
'A',
'B',
'A',
'A'),
1109 '2'=>array(
'B',
'B',
'A',
'A',
'B',
'A'),
1110 '3'=>array(
'B',
'B',
'A',
'A',
'A',
'B'),
1111 '4'=>array(
'B',
'A',
'B',
'B',
'A',
'A'),
1112 '5'=>array(
'B',
'A',
'A',
'B',
'B',
'A'),
1113 '6'=>array(
'B',
'A',
'A',
'A',
'B',
'B'),
1114 '7'=>array(
'B',
'A',
'B',
'A',
'B',
'A'),
1115 '8'=>array(
'B',
'A',
'B',
'A',
'A',
'B'),
1116 '9'=>array(
'B',
'A',
'A',
'B',
'A',
'B')
1118 $upce_parities[1] = array(
1119 '0'=>array(
'A',
'A',
'A',
'B',
'B',
'B'),
1120 '1'=>array(
'A',
'A',
'B',
'A',
'B',
'B'),
1121 '2'=>array(
'A',
'A',
'B',
'B',
'A',
'B'),
1122 '3'=>array(
'A',
'A',
'B',
'B',
'B',
'A'),
1123 '4'=>array(
'A',
'B',
'A',
'A',
'B',
'B'),
1124 '5'=>array(
'A',
'B',
'B',
'A',
'A',
'B'),
1125 '6'=>array(
'A',
'B',
'B',
'B',
'A',
'A'),
1126 '7'=>array(
'A',
'B',
'A',
'B',
'A',
'B'),
1127 '8'=>array(
'A',
'B',
'A',
'B',
'B',
'A'),
1128 '9'=>array(
'A',
'B',
'B',
'A',
'B',
'A')
1133 $bararray = array(
'code' => $upce_code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1134 $p = $upce_parities[$code{1}][$r];
1135 for ($i = 0; $i < 6; ++$i) {
1136 $seq .= $codes[$p[$i]][$upce_code{$i}];
1140 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1141 $half_len = ceil($len / 2);
1143 for ($i = 0; $i < $half_len; ++$i) {
1144 $seq .= $codes[
'A'][$code{$i}];
1147 $p = $parities[$code{0}];
1148 for ($i = 1; $i < $half_len; ++$i) {
1149 $seq .= $codes[$p[$i-1]][$code{$i}];
1153 for ($i = $half_len; $i < $len; ++$i) {
1154 $seq .= $codes[
'C'][$code{$i}];
1158 $clen = strlen($seq);
1160 for ($i = 0; $i < $clen; ++$i) {
1162 if (($i == ($clen - 1)) OR (($i < ($clen - 1)) AND ($seq{$i} != $seq{($i+1)}))) {
1163 if ($seq{$i} ==
'1') {
1168 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
1169 $bararray[
'maxw'] += $w;
1188 $code = str_pad($code, $len,
'0', STR_PAD_LEFT);
1193 $r = (3 * ($code{0} + $code{2} + $code{4})) + (9 * ($code{1} + $code{3}));
1223 $parities = array();
1224 $parities[2] = array(
1225 '0'=>array(
'A',
'A'),
1226 '1'=>array(
'A',
'B'),
1227 '2'=>array(
'B',
'A'),
1230 $parities[5] = array(
1231 '0'=>array(
'B',
'B',
'A',
'A',
'A'),
1232 '1'=>array(
'B',
'A',
'B',
'A',
'A'),
1233 '2'=>array(
'B',
'A',
'A',
'B',
'A'),
1234 '3'=>array(
'B',
'A',
'A',
'A',
'B'),
1235 '4'=>array(
'A',
'B',
'B',
'A',
'A'),
1236 '5'=>array(
'A',
'A',
'B',
'B',
'A'),
1237 '6'=>array(
'A',
'A',
'A',
'B',
'B'),
1238 '7'=>array(
'A',
'B',
'A',
'B',
'A'),
1239 '8'=>array(
'A',
'B',
'A',
'A',
'B'),
1240 '9'=>array(
'A',
'A',
'B',
'A',
'B')
1242 $p = $parities[$len][$r];
1244 $seq .= $codes[$p[0]][$code{0}];
1245 for ($i = 1; $i < $len; ++$i) {
1247 $seq .= $codes[$p[$i]][$code{$i}];
1249 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1265 0 => Array(1,1,2,2,2),
1266 1 => Array(2,2,2,1,1),
1267 2 => Array(2,2,1,2,1),
1268 3 => Array(2,2,1,1,2),
1269 4 => Array(2,1,2,2,1),
1270 5 => Array(2,1,2,1,2),
1271 6 => Array(2,1,1,2,2),
1272 7 => Array(1,2,2,2,1),
1273 8 => Array(1,2,2,1,2),
1274 9 => Array(1,2,1,2,2)
1278 0 => Array(2,2,1,1,1),
1279 1 => Array(1,1,1,2,2),
1280 2 => Array(1,1,2,1,2),
1281 3 => Array(1,1,2,2,1),
1282 4 => Array(1,2,1,1,2),
1283 5 => Array(1,2,1,2,1),
1284 6 => Array(1,2,2,1,1),
1285 7 => Array(2,1,1,1,2),
1286 8 => Array(2,1,1,2,1),
1287 9 => Array(2,1,2,1,1)
1290 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 2,
'bcode' => array());
1292 $code = str_replace(
'-',
'', $code);
1293 $code = str_replace(
' ',
'', $code);
1294 $len = strlen($code);
1297 for ($i = 0; $i < $len; ++$i) {
1298 $sum += intval($code{$i});
1300 $chkd = ($sum % 10);
1302 $chkd = (10 - $chkd);
1305 $len = strlen($code);
1307 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => 2,
'p' => 0);
1308 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1309 $bararray[
'maxw'] += 2;
1310 for ($i = 0; $i < $len; ++$i) {
1311 for ($j = 0; $j < 5; ++$j) {
1312 $h = $barlen[$code{$i}][$j];
1314 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => $h,
'p' => $p);
1315 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1316 $bararray[
'maxw'] += 2;
1320 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => 2,
'p' => 0);
1321 $bararray[
'maxw'] += 1;
1342 '0' => array(3,3,2,2),
1343 '1' => array(3,4,1,2),
1344 '2' => array(3,4,2,1),
1345 '3' => array(4,3,1,2),
1346 '4' => array(4,3,2,1),
1347 '5' => array(4,4,1,1),
1348 '6' => array(3,1,4,2),
1349 '7' => array(3,2,3,2),
1350 '8' => array(3,2,4,1),
1351 '9' => array(4,1,3,2),
1352 'A' => array(4,1,4,1),
1353 'B' => array(4,2,3,1),
1354 'C' => array(3,1,2,4),
1355 'D' => array(3,2,1,4),
1356 'E' => array(3,2,2,3),
1357 'F' => array(4,1,1,4),
1358 'G' => array(4,1,2,3),
1359 'H' => array(4,2,1,3),
1360 'I' => array(1,3,4,2),
1361 'J' => array(1,4,3,2),
1362 'K' => array(1,4,4,1),
1363 'L' => array(2,3,3,2),
1364 'M' => array(2,3,4,1),
1365 'N' => array(2,4,3,1),
1366 'O' => array(1,3,2,4),
1367 'P' => array(1,4,1,4),
1368 'Q' => array(1,4,2,3),
1369 'R' => array(2,3,1,4),
1370 'S' => array(2,3,2,3),
1371 'T' => array(2,4,1,3),
1372 'U' => array(1,1,4,4),
1373 'V' => array(1,2,3,4),
1374 'W' => array(1,2,4,3),
1375 'X' => array(2,1,3,4),
1376 'Y' => array(2,1,4,3),
1377 'Z' => array(2,2,3,3)
1379 $code = strtoupper($code);
1380 $len = strlen($code);
1381 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 3,
'bcode' => array());
1384 $checktable = array(
1424 for ($i = 0; $i < $len; ++$i) {
1425 $row += $checktable[$code{$i}][0];
1426 $col += $checktable[$code{$i}][1];
1430 $chk = array_keys($checktable, array(
$row,$col));
1437 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => 2,
'p' => 0);
1438 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1439 $bararray[
'maxw'] += 2;
1441 for ($i = 0; $i < $len; ++$i) {
1442 for ($j = 0; $j < 4; ++$j) {
1443 switch ($barmode[$code{$i}][$j]) {
1465 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => $h,
'p' => $p);
1466 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1467 $bararray[
'maxw'] += 2;
1472 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => 3,
'p' => 0);
1473 $bararray[
'maxw'] += 1;
1508 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1512 $code =
'A'.strtoupper($code).
'A';
1513 $len = strlen($code);
1514 for ($i = 0; $i < $len; ++$i) {
1515 if (!isset($chr[$code{$i}])) {
1518 $seq = $chr[$code{$i}];
1519 for ($j = 0; $j < 8; ++$j) {
1520 if (($j % 2) == 0) {
1526 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
1527 $bararray[
'maxw'] += $w;
1557 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1561 $len = strlen($code);
1565 for ($i = ($len - 1); $i >= 0; --$i) {
1567 if ($digit ==
'-') {
1570 $dval = intval($digit);
1572 $check += ($dval * $p);
1587 for ($i = $len; $i >= 0; --$i) {
1589 if ($digit ==
'-') {
1592 $dval = intval($digit);
1594 $check += ($dval * $p);
1604 $code =
'S'.$code.
'S';
1606 for ($i = 0; $i < $len; ++$i) {
1607 if (!isset($chr[$code{$i}])) {
1610 $seq = $chr[$code{$i}];
1611 for ($j = 0; $j < 6; ++$j) {
1612 if (($j % 2) == 0) {
1618 $bararray[
'bcode'][$k] = array(
't' =>
$t,
'w' => $w,
'h' => 1,
'p' => 0);
1619 $bararray[
'maxw'] += $w;
1635 $code = intval($code);
1637 if (($code % 2) == 0) {
1646 $seq = substr($seq, 0, -2);
1647 $seq = strrev($seq);
1648 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 1,
'bcode' => array());
1661 $code = intval($code);
1663 switch ($code % 3) {
1666 $code = ($code - 3) / 3;
1671 $code = ($code - 1) / 3;
1676 $code = ($code - 2) / 3;
1680 }
while($code != 0);
1681 $seq = strrev($seq);
1683 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 2,
'bcode' => array());
1684 $len = strlen($seq);
1685 for ($i = 0; $i < $len; ++$i) {
1703 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => $h,
'p' => $p);
1704 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1705 $bararray[
'maxw'] += 2;
1707 unset($bararray[
'bcode'][($k - 1)]);
1708 --$bararray[
'maxw'];
1723 $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);
1724 $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);
1725 $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);
1726 $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);
1727 $code_arr = explode(
'-', $code);
1728 $tracking_number = $code_arr[0];
1729 if (isset($code_arr[1])) {
1730 $routing_code = $code_arr[1];
1735 switch (strlen($routing_code)) {
1741 $binary_code = bcadd($routing_code,
'1');
1745 $binary_code = bcadd($routing_code,
'100001');
1749 $binary_code = bcadd($routing_code,
'1000100001');
1757 $binary_code = bcmul($binary_code, 10);
1758 $binary_code = bcadd($binary_code, $tracking_number{0});
1759 $binary_code = bcmul($binary_code, 5);
1760 $binary_code = bcadd($binary_code, $tracking_number{1});
1761 $binary_code .= substr($tracking_number, 2, 18);
1763 $binary_code = $this->
dec_to_hex($binary_code);
1765 $binary_code = str_pad($binary_code, 26,
'0', STR_PAD_LEFT);
1767 $binary_code_arr = chunk_split($binary_code, 2,
"\r");
1768 $binary_code_arr = substr($binary_code_arr, 0, -1);
1769 $binary_code_arr = explode(
"\r", $binary_code_arr);
1773 $first_byte = sprintf(
'%2s', dechex((hexdec($binary_code_arr[0]) << 2) >> 2));
1774 $binary_code_102bit = $first_byte.substr($binary_code, 2);
1776 $codewords = array();
1778 $codewords[0] = bcmod(
$data, 636) * 2;
1780 for ($i = 1; $i < 9; ++$i) {
1781 $codewords[$i] = bcmod(
$data, 1365);
1784 $codewords[9] =
$data;
1785 if (($fcs >> 10) == 1) {
1786 $codewords[9] += 659;
1792 $characters = array();
1794 foreach($codewords as $k => $val) {
1796 $chrcode = $table5of13[$val];
1798 $chrcode = $table2of13[($val - 1287)];
1800 if (($fcs & $bitmask) > 0) {
1802 $chrcode = ((~$chrcode) & 8191);
1804 $characters[] = $chrcode;
1807 $characters = array_reverse($characters);
1810 $bararray = array(
'code' => $code,
'maxw' => 0,
'maxh' => 3,
'bcode' => array());
1811 for ($i = 0; $i < 65; ++$i) {
1812 $asc = (($characters[$asc_chr[$i]] & pow(2, $asc_pos[$i])) > 0);
1813 $dsc = (($characters[$dsc_chr[$i]] & pow(2, $dsc_pos[$i])) > 0);
1814 if ($asc AND $dsc) {
1831 $bararray[
'bcode'][$k++] = array(
't' => 1,
'w' => 1,
'h' => $h,
'p' => $p);
1832 $bararray[
'bcode'][$k++] = array(
't' => 0,
'w' => 1,
'h' => 2,
'p' => 0);
1833 $bararray[
'maxw'] += 2;
1835 unset($bararray[
'bcode'][($k - 1)]);
1836 --$bararray[
'maxw'];
1852 while($number > 0) {
1854 array_push($hex,
'0');
1856 array_push($hex, strtoupper(dechex(bcmod($number,
'16'))));
1857 $number = bcdiv($number,
'16', 0);
1860 $hex = array_reverse($hex);
1861 return implode($hex);
1873 $len = strlen($hex);
1874 for($pos = ($len - 1); $pos >= 0; --$pos) {
1875 $dec = bcadd($dec, bcmul(hexdec($hex{$pos}), $bitval));
1876 $bitval = bcmul($bitval, 16);
1891 $data = hexdec($code_arr[0]) << 5;
1892 for ($bit = 2; $bit < 8; ++$bit) {
1893 if (($fcs ^
$data) & 0x400) {
1894 $fcs = ($fcs << 1) ^ $genpoly;
1902 for ($byte = 1; $byte < 13; ++$byte) {
1903 $data = hexdec($code_arr[$byte]) << 3;
1904 for ($bit = 0; $bit < 8; ++$bit) {
1905 if (($fcs ^
$data) & 0x400) {
1906 $fcs = ($fcs << 1) ^ $genpoly;
1925 for ($i = 0; $i < 16; ++$i) {
1944 for ($count = 0; $count < 8192; ++$count) {
1946 for ($bit_index = 0; $bit_index < 13; ++$bit_index) {
1947 $bit_count += intval(($count & (1 << $bit_index)) != 0);
1950 if ($bit_count ==
$n) {
1953 if ($reverse >= $count) {
1956 if ($reverse == $count) {
1957 $table[$lui] = $count;
1960 $table[$lli] = $count;
1962 $table[$lli] = $reverse;