format_size

Definition

format_size($size)
includes/common.inc, line 849

Description

Generate a string representation for the given byte count.

Parameters

$size The size in bytes.

Return value

A translated string representation of the size.

Related topics

Namesort iconDescription
FormattingFunctions to format numbers, strings, dates, etc.
Input validationFunctions to validate user input.

Code

<?php
function format_size($size) {
  $suffix = t('bytes');
  if ($size >= 1024) {
    $size = round($size / 1024, 2);
    $suffix = t('KB');
  }
  if ($size >= 1024) {
    $size = round($size / 1024, 2);
    $suffix = t('MB');
  }
  return t('%size %suffix', array('%size' => $size, '%suffix' => $suffix));
}
?>
 
 

All source code and documentation on this site is released under the terms of the GNU General Public License, version 2 and later. Drupal is a registered trademark of Dries Buytaert.