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!
Format MAC address - Desprate
Moderator: General Moderators
Re: Format MAC address - Desprate
Take a look at explode() function
There are 10 types of people in this world, those who understand binary and those who don't
Re: Format MAC address - Desprate
Could you explain this in more details? Where do you get these ports/MAC addresses from?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.
There are 10 types of people in this world, those who understand binary and those who don't
Re: Format MAC address - Desprate
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
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()
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()
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: Format MAC address - Desprate
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
You concatenate strings with "."
Code: Select all
$a = 'A';
$b = 'B'
$c = $a.$b;
//$c now equals ABReal programmers don't comment their code. If it was hard to write, it should be hard to understand.