Jump to content

Archived

This topic is now archived and is closed to further replies.

tomasd

changing key and value inside array

Recommended Posts

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

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]I've looked for array functions but could not find right one.[/i]
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!!!

Share this post


Link to post
Share on other sites
try this..

[code]<?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);

?>[/code]untested.

Share this post


Link to post
Share on other sites
thanks a lot apart from
$sys = array_flip($sys);
everything is ok, woks just well!!!

Share this post


Link to post
Share on other sites

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

[code]
snmp_set_oid_numeric_print(1);
snmp_set_quick_print(TRUE);
snmp_set_enum_print(TRUE);
snmp_set_valueretrieval(SNMP_VALUE_PLAIN);
[/code]

- Brian

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.