original_string: public function parseSnmpValue($v) {
          // first, rule out an empty string
          if ($v == '""' || $v == '') {
              return "";
          }
  
          $type = substr($v, 0, strpos($v, ':'));
          $value = trim(substr($v, strpos($v, ':') + 1));
  
          switch ($type) {
              case 'STRING':
                  if (substr($value, 0, 1) == '"') {
                      $rtn = (string) trim(substr(substr($value, 1), 0, -1));
                  } else {
                      $rtn = (string) $value;
                  }
                  break;
  
              case 'INTEGER':
                  if (!is_numeric($value)) {
                      // find the first digit and offset the string to that point
                      // just in case there is some mib strangeness going on
                      preg_match('/\d/', $value, $m, PREG_OFFSET_CAPTURE);
                      $rtn = (int) substr($value, $m[0][1]);
                  } else {
                      $rtn = (int) $value;
                  }
                  break;
  
              case 'Counter32':
                  $rtn = (int) $value;
                  break;
  
              case 'Counter64':
                  $rtn = (int) $value;
                  break;
  
              case 'Gauge32':
                  $rtn = (int) $value;
                  break;
  
              case 'Hex-STRING':
                  $rtn = (string) implode('', explode(' ', preg_replace('/[^A-Fa-f0-9]/', '', $value)));
                  break;
  
              case 'IpAddress':
                  $rtn = (string) $value;
                  break;
  
              case 'OID':
                  $rtn = (string) $value;
                  break;
  
              case 'Timeticks':
                  $rtn = (int) substr($value, 1, strrpos($value, ')') - 1);
                  break;
  
              default:
                  throw new Exception("ERR: Unhandled SNMP return type: $type\n");
          }
  
          return $rtn;
      }
code: public function parseSnmpValue($v) {
          // first, rule out an empty string
          if ($v == '""' || $v == '') {
              return "";
          }
  
          $type = substr($v, 0, strpos($v, ':'));
          $value = trim(substr($v, strpos($v, ':') + 1));
  
          switch ($type) {
              case 'STRING':
                  if (substr($value, 0, 1) == '"') {
                      $rtn = (string) trim(substr(substr($value, 1), 0, -1));
                  } else {
                      $rtn = (string) $value;
                  }
                  break;
  
              case 'INTEGER':
                  if (!is_numeric($value)) {
                      // find the first digit and offset the string to that point
                      // just in case there is some mib strangeness going on
                      preg_match('/\d/', $value, $m, PREG_OFFSET_CAPTURE);
                      $rtn = (int) substr($value, $m[0][1]);
                  } else {
                      $rtn = (int) $value;
                  }
                  break;
  
              case 'Counter32':
                  $rtn = (int) $value;
                  break;
  
              case 'Counter64':
                  $rtn = (int) $value;
                  break;
  
              case 'Gauge32':
                  $rtn = (int) $value;
                  break;
  
              case 'Hex-STRING':
                  $rtn = (string) implode('', explode(' ', preg_replace('/[^A-Fa-f0-9]/', '', $value)));
                  break;
  
              case 'IpAddress':
                  $rtn = (string) $value;
                  break;
  
              case 'OID':
                  $rtn = (string) $value;
                  break;
  
              case 'Timeticks':
                  $rtn = (int) substr($value, 1, strrpos($value, ')') - 1);
                  break;
  
              default:
                  throw new Exception("ERR: Unhandled SNMP return type: $type\n");
          }
  
          return $rtn;
      }
code_tokens: public function parseSnmpValue ( $ v ) { // first, rule out an empty string if ( $ v == '""' || $ v == '' ) { return "" ; } $ type = substr ( $ v , 0 , strpos ( $ v , ':' ) ) ; $ value = trim ( substr ( $ v , strpos ( $ v , ':' ) + 1 ) ) ; switch ( $ type ) { case 'STRING' : if ( substr ( $ value , 0 , 1 ) == '"' ) { $ rtn = ( string ) trim ( substr ( substr ( $ value , 1 ) , 0 , - 1 ) ) ; } else { $ rtn = ( string ) $ value ; } break ; case 'INTEGER' : if ( ! is_numeric ( $ value ) ) { // find the first digit and offset the string to that point // just in case there is some mib strangeness going on preg_match ( '/\d/' , $ value , $ m , PREG_OFFSET_CAPTURE ) ; $ rtn = ( int ) substr ( $ value , $ m [ 0 ] [ 1 ] ) ; } else { $ rtn = ( int ) $ value ; } break ; case 'Counter32' : $ rtn = ( int ) $ value ; break ; case 'Counter64' : $ rtn = ( int ) $ value ; break ; case 'Gauge32' : $ rtn = ( int ) $ value ; break ; case 'Hex-STRING' : $ rtn = ( string ) implode ( '' , explode ( ' ' , preg_replace ( '/[^A-Fa-f0-9]/' , '' , $ value ) ) ) ; break ; case 'IpAddress' : $ rtn = ( string ) $ value ; break ; case 'OID' : $ rtn = ( string ) $ value ; break ; case 'Timeticks' : $ rtn = ( int ) substr ( $ value , 1 , strrpos ( $ value , ')' ) - 1 ) ; break ; default : throw new Exception ( "ERR: Unhandled SNMP return type: $type\n" ) ; } return $ rtn ; }
docstring: Parse the result of an SNMP query into a PHP type
  
  For example, [STRING: "blah"] is parsed to a PHP string containing: blah
  
  @param string $v The value to parse
  @return mixed The parsed value
  @throws Exception
docstring_tokens: Parse the result of an SNMP query into a PHP type