function parse_size
7.x common.inc | parse_size($size) |
6.x common.inc | parse_size($size) |
Parse a given byte count.
Parameters
$size: A size expressed as a number of bytes with optional SI size and unit suffix (e.g. 2, 3K, 5MB, 10G).
Return value
An integer representation of the size.
Related topics
3 calls to parse_size()
- color_scheme_form_submit in drupal-6.x/
modules/ color/ color.module - Submit handler for color change form.
- file_upload_max_size in drupal-6.x/
includes/ file.inc - Determine the maximum file upload size by querying the PHP settings.
- system_requirements in drupal-6.x/
modules/ system/ system.install - Implementation of hook_requirements().
File
- drupal-6.x/
includes/ common.inc, line 1260 - Common functions that many Drupal modules will need to reference.
Code
function parse_size($size) {
$suffixes = array(
'' => 1,
'k' => 1024,
'm' => 1048576, // 1024 * 1024
'g' => 1073741824, // 1024 * 1024 * 1024
);
if (preg_match('/([0-9]+)\s*(k|m|g)?(b?(ytes?)?)/i', $size, $match)) {
return $match[1] * $suffixes[drupal_strtolower($match[2])];
}
}