All pastes #290394 Raw Edit

Miscellany

public php v1 · immutable
#290394 ·published 2006-12-23 23:46 UTC
rendered paste body
<?php/* One of several batches of data I've been using to test:1111111111111123456795405012345689640511234569974052123457098405312345716040541234572614055123457362405612345746340571234575644058123457665405912345776640601234578674061111111111111111111111111111234579684062123458069406312345817040641234582714065123458372406612345847340671111111111111*///takes an array of barcodes as input,//returns an array in which each element//is a three-element array, the first//element being a cartonid, the second//an originid, and the third the store numberfunction barcode_parse($bar_arr_input) {  $bar_obj = array();  foreach ($bar_arr_input as $n) {    $bar_item = array();    array_push($bar_item, substr($n, 0, 7));    array_push($bar_item, substr($n, 7, 2));    array_push($bar_item, substr($n, 9, 4));    array_push($bar_obj, $bar_item);    unset($bar_item);  }  return $bar_obj;}// a function to test an array of raw barcodes// we're specifically looking for '1111111111111'// _only_ at the beginning and end of the array.// if it's missing in those places or shows up// elsewhere, throw an error.function barcode_test($arr_to_test) {  $endcap0 = "1111111111111\n";  $endcap1 = "1111111111111";  $first = array_shift($arr_to_test);  // check the first item  if ((strstr($first, $endcap0)) || (strstr($first, $endcap1))) {    // first item matched, continue    $last = array_pop($arr_to_test);    // check the last item    if ((strstr($last, $endcap0)) || (strstr($last, $endcap1))) {      // last item matched, continue      // now we search for '1111111111111' in the middle      // if we find it, that's bad (forgot to clear memory in barcode reader)      if ((in_array($endcap0, $arr_to_test)) || (in_array($endcap1, $arr_to_test))) {        return "ERR3"; // echo "Failed!\nYou forgot to clear the reader!\n";      } else {        //echo "Success!\n You've got a valid dump!\n";        return $arr_to_test;      }    } else {      return "ERR1"; // echo "Failed!\nLast item not 1111111111111\n";    }  } else {    return "ERR0"; // echo "Failed!\nFirst item not 1111111111111\n";  }}$numbers = explode("\n", htmlentities($_POST[bcodeinput]));// do we have a valid batch of numbers?$numbers = barcode_test($numbers);if (strstr($numbers, "ERR0")) {  die("Failed!\nFirst item not 1111111111111\n");} elseif (strstr($numbers, "ERR1")) {  die("Failed!\nLast item not 1111111111111\n");} elseif (strstr($numbers, "ERR3")) {  die("Failed!\nYou forgot to clear the reader!\n");} else {  $bar_obj = barcode_parse($numbers);}?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>  <link rel="stylesheet" type="text/css" href="screen.css" media="screen" />  <link rel="stylesheet" type="text/css" href="print.css" media="print" />  <meta content="text/html; charset=ISO-8859-1"  http-equiv="content-type" /><title></title></head><body><div class="bodyContainer"><?php echo "<pre>"; ?><?php/*if (in_array("1111111111111", $numbers)) {  echo "Success!\n";} else {  echo "Damnit!\n";}*/print_r($numbers);?><?phpprint_r($bar_obj);?></div></html>