Jump to content


Photo

changing key and value inside array


  • Please log in to reply
3 replies to this topic

#1 tomasd

tomasd
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 15 August 2006 - 08:56 AM

Hi,
I have this code here
<?php
$sys = snmprealwalk("192.168.100.100", "cisco1720", ".1.3.6.1.2.1.17");
$sys = array_flip($sys);
print_r ($sys);
?>

Which on execution produces:[pre] [wally@macppc dhcp]$ php test.php
Array
(
    [Hex-STRING: 00 04 DC 0C EA AF ] => SNMPv2-SMI::mib-2.17.1.1.0
)[/pre] My questions are:
how to get rid of "Hex-STRING: " and last space " " from the key and "SNMPv2-SMI::" from the value within the array itself?
I've looked for array functions but could not find right one.
how to insert ":" beween xx xx xx xx xx so I get right mac address notation i.e. xx:xx:xx:xx:xx

Thanks everyone for your help!!!


#2 Jenk

Jenk
  • Members
  • PipPipPip
  • Advanced Member
  • 778 posts

Posted 15 August 2006 - 09:28 AM

try this..

<?php

function formatArray ($array)
{
    if (!is_array($array)) return false;

    $return = array();

    foreach ($array as $key => $val)
    {
        $key = trim(substr($key, 12));
        $val = trim(substr($val, 12));

        $key = str_replace(' ', ':', $key);

        $return[$key] = $val;
    }

    return $return;
}

$sys = snmprealwalk("192.168.100.100", "cisco1720", ".1.3.6.1.2.1.17");
$sys = formatArray($sys);

?>
untested.

#3 tomasd

tomasd
  • Members
  • PipPipPip
  • Advanced Member
  • 86 posts

Posted 15 August 2006 - 09:41 AM

thanks a lot apart from
$sys = array_flip($sys);
everything is ok, woks just well!!!


#4 shazam

shazam
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 05 December 2006 - 02:24 PM


FYI.  You may want to try playing wit a few of these functions as well:

snmp_set_oid_numeric_print(1);
snmp_set_quick_print(TRUE);
snmp_set_enum_print(TRUE);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);

- Brian




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users