mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
refactor: small function cleanups (#5865)
found while working on my snmp refactor mac_clean_to_readable is about 33% improvement hex2str is a moderate improvement
This commit is contained in:
committed by
Neil Lathwood
parent
3c7792a170
commit
a75ec7ab31
@@ -65,14 +65,7 @@ function array_sort($array, $on, $order = SORT_ASC)
|
|||||||
|
|
||||||
function mac_clean_to_readable($mac)
|
function mac_clean_to_readable($mac)
|
||||||
{
|
{
|
||||||
$r = substr($mac, 0, 2);
|
return rtrim(chunk_split($mac, 2, ':'), ':');
|
||||||
$r .= ":".substr($mac, 2, 2);
|
|
||||||
$r .= ":".substr($mac, 4, 2);
|
|
||||||
$r .= ":".substr($mac, 6, 2);
|
|
||||||
$r .= ":".substr($mac, 8, 2);
|
|
||||||
$r .= ":".substr($mac, 10, 2);
|
|
||||||
|
|
||||||
return($r);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function only_alphanumeric($string)
|
function only_alphanumeric($string)
|
||||||
@@ -910,13 +903,12 @@ function formatCiscoHardware(&$device, $short = false)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# from http://ditio.net/2008/11/04/php-string-to-hex-and-hex-to-string-functions/
|
|
||||||
function hex2str($hex)
|
function hex2str($hex)
|
||||||
{
|
{
|
||||||
$string='';
|
$string='';
|
||||||
|
|
||||||
for ($i = 0; $i < strlen($hex)-1; $i+=2) {
|
for ($i = 0; $i < strlen($hex)-1; $i+=2) {
|
||||||
$string .= chr(hexdec($hex[$i].$hex[$i+1]));
|
$string .= chr(hexdec(substr($hex, $i, 2)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return $string;
|
return $string;
|
||||||
|
Reference in New Issue
Block a user