1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| $chksum = 105; $code_array = array("00"=>"212222","01"=>"222122","02"=>"222221","03"=>"121223","04"=>"121322","05"=>"131222","06"=>"122213","07"=>"122312","08"=>"132212","09"=>"221213","10"=>"221312","11"=>"231212","12"=>"112232","13"=>"122132","14"=>"122231","15"=>"113222","16"=>"123122","17"=>"123221","18"=>"223211","19"=>"221132","20"=>"221231","21"=>"213212","22"=>"223112","23"=>"312131","24"=>"311222","25"=>"321122","26"=>"321221","27"=>"312212","28"=>"322112","29"=>"322211","30"=>"212123","31"=>"212321","32"=>"232121","33"=>"111323","34"=>"131123","35"=>"131321","36"=>"112313","37"=>"132113","38"=>"132311","39"=>"211313","40"=>"231113","41"=>"231311","42"=>"112133","43"=>"112331","44"=>"132131","45"=>"113123","46"=>"113321","47"=>"133121","48"=>"313121","49"=>"211331","50"=>"231131","51"=>"213113","52"=>"213311","53"=>"213131","54"=>"311123","55"=>"311321","56"=>"331121","57"=>"312113","58"=>"312311","59"=>"332111","60"=>"314111","61"=>"221411","62"=>"431111","63"=>"111224","64"=>"111422","65"=>"121124","66"=>"121421","67"=>"141122","68"=>"141221","69"=>"112214","70"=>"112412","71"=>"122114","72"=>"122411","73"=>"142112","74"=>"142211","75"=>"241211","76"=>"221114","77"=>"413111","78"=>"241112","79"=>"134111","80"=>"111242","81"=>"121142","82"=>"121241","83"=>"114212","84"=>"124112","85"=>"124211","86"=>"411212","87"=>"421112","88"=>"421211","89"=>"212141","90"=>"214121","91"=>"412121","92"=>"111143","93"=>"111341","94"=>"131141","95"=>"114113","96"=>"114311","97"=>"411113","98"=>"411311","99"=>"113141","CODE B"=>"114131","CODE A"=>"311141","FNC 1"=>"411131","Start A"=>"211412","Start B"=>"211214","Start C"=>"211232","Stop"=>"2331112"); $code_keys = array_keys($code_array); $code_values = array_flip($code_keys); $strlen = strlen($text); for ($i = 1; $i <= $strlen; $i = $i + 2) { $active_key = substr( $text, ($i-1), 2); if ($i == $strlen) { $code_array_b = array("0"=>"123122","1"=>"123221","2"=>"223211","3"=>"221132","4"=>"221231","5"=>"213212","6"=>"223112","7"=>"312131","8"=>"311222","9"=>"321122"); $code_values_b = array("0"=>16,"1"=>17,"2"=>18,"3"=>19,"4"=>20,"5"=>21,"6"=>22,"7"=>23,"8"=>24,"9"=>25); $code_string .= $code_array['CODE B'] . $code_array_b[$active_key]; $chksum += $code_values['CODE B'] * ($i + 1) / 2 + $code_values_b[$active_key] * ($i + 3) / 2; } else { $code_string .= $code_array[$active_key]; $chksum += $code_values[$active_key] * ($i + 1) / 2; } } $code_string .= $code_array[$code_keys[$chksum % 103]]; $code_string = "211232" . $code_string . "2331112";
|