| 5 common.inc | format_size($size) |
| 6 common.inc | format_size($size, $langcode = NULL) |
| 7 common.inc | format_size($size, $langcode = NULL) |
| 8 common.inc | format_size($size, $langcode = NULL) |
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
File
- includes/
common.inc, line 1145 - Common functions that many Drupal modules will need to reference.
Code
<?php
function format_size($size) {
if ($size < 1024) {
return format_plural($size, '1 byte', '@count bytes');
}
else {
$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));
}
}
?>Login or register to post comments