tomasd Posted August 15, 2006 Share Posted August 15, 2006 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.phpArray( [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:xxThanks everyone for your help!!! Link to comment https://forums.phpfreaks.com/topic/17597-changing-key-and-value-inside-array/ Share on other sites More sharing options...
Jenk Posted August 15, 2006 Share Posted August 15, 2006 try this..[code]<?phpfunction 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. Link to comment https://forums.phpfreaks.com/topic/17597-changing-key-and-value-inside-array/#findComment-74998 Share on other sites More sharing options...
tomasd Posted August 15, 2006 Author Share Posted August 15, 2006 thanks a lot apart from $sys = array_flip($sys);everything is ok, woks just well!!! Link to comment https://forums.phpfreaks.com/topic/17597-changing-key-and-value-inside-array/#findComment-75001 Share on other sites More sharing options...
shazam Posted December 5, 2006 Share Posted December 5, 2006 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 Link to comment https://forums.phpfreaks.com/topic/17597-changing-key-and-value-inside-array/#findComment-135460 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.