Page 1 of 1
Format MAC address - Desprate
Posted: Wed Mar 04, 2009 2:19 pm
by jkubena
all i want to do is format an array of these
0:20:d6:83:57:95
and turn it into an array of these
00 20 D6 83 57 95
i need one string formatted like the other or visa versa.
this will allow me to compare a port to mac address table with an IP to mac address table to figure out the IP of the device on the port.
Please help, im begging you!
Re: Format MAC address - Desprate
Posted: Wed Mar 04, 2009 3:28 pm
by VladSun
Take a look at explode() function
Re: Format MAC address - Desprate
Posted: Wed Mar 04, 2009 3:29 pm
by VladSun
jkubena wrote:this will allow me to compare a port to mac address table with an IP to mac address table to figure out the IP of the device on the port.
Could you explain this in more details? Where do you get these ports/MAC addresses from?
Re: Format MAC address - Desprate
Posted: Wed Mar 04, 2009 4:30 pm
by jkubena
i do a shell exec and run an SNMP query, some of the macs come back formatted differently. i do know how to use the explode function very well, i tried exploding the mac address and then searching the string array and if the string length is 1 prepend a 0 on it, then implode it back to mac address form. but php is a retarded language and it doesn't know the difference between a string and an int so it just adds a zero to it sometimes, sometimes it works, other times it doesn't.
Re: Format MAC address - Desprate
Posted: Thu Mar 05, 2009 10:26 am
by pickle
Um... you're on a PHP forum - calling PHP a retarded language isn't likely going to help you make friends here
If you've got an array of those strings, just loop through those strings & do a
str_replace() to replace ':' with ' ', then run them through
strtoupper()
Re: Format MAC address - Desprate
Posted: Thu Mar 05, 2009 11:53 am
by jkubena
sorry im a bit frustrated. but i also need to add zeros too, i would be really easy if thats all i had to do, i wanna to like a $str = 0$str if the str length is one after i explode by ":". but all it does it add the two numbers together.
Re: Format MAC address - Desprate
Posted: Thu Mar 05, 2009 1:36 pm
by pickle
You concatenate strings with "."
Code: Select all
$a = 'A';
$b = 'B'
$c = $a.$b;
//$c now equals AB