Useful scripts and PHP features that are collected during application development
How to format file size
function formatBytes($size, $precision = 2) { $base = log($size, 1024); $suffixes = array('', 'K', 'M', 'G', 'T'); return round(pow(1024, $base - floor($base)), $precision) .' '. $suffixes[floor($base)]; }
How to format MAC Address
function AddSeparator($mac, $separator = ':') { $result2 = ''; while (strlen($mac) > 0) { $sub = substr($mac, 0, 2); $result2 .= $sub . $separator; $mac = substr($mac, 2, strlen($mac)); } // remove trailing colon $result2 = substr($result2, 0, strlen($result2) - 1); return $result2; }