Skip to content

Instantly share code, notes, and snippets.

@ollym
Created December 30, 2009 21:51
Show Gist options
  • Save ollym/266431 to your computer and use it in GitHub Desktop.
Save ollym/266431 to your computer and use it in GitHub Desktop.
public static function memory($bytes, $places = 2)
{
static $suffexes = array(
'B', 'KB', 'MB', 'GB', 'TB', 'PB'
);
$i = 0;
while ($bytes > 10)
{
$bytes /= 1024;
$i++;
if ( ! isset($suffexes[$i]))
{
break;
}
}
return round($bytes, $places).$suffexes[$i];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment