I have a script which is to display the MAC Address for a peice of equipment with info pulled from a MySQL database. I want to display it is proper notation, which is:
xx:xx:xx:xx:xx:xx
When the info is placed in the database, the colons are not added. I want to display with the colons. How do I take the content of the variable "$mac_address" which is for example "000625122117" and display it as "00:06:25:12:21:17"
Thank you for your help in advance,
Phil
For some reason, this seems like overkill, but oh well
<?php function splitMac($mac) { $array = array(); for($i=0;$i<strlen($mac);$i=$i+2) { $array[] = substr($mac,$i,2); } return $array; } $mac = "000625122117"; $format = implode(":", splitMac($mac)); echo $format; ?>
echo substr($mac_adress,0,2).":". substr($mac_adress,2,2).":". substr($mac_adress,4,2).":". substr($mac_adress,6,2).":". substr($mac_adress,8,2);
That last post was the simplist and worked. Many thanks,