Parses a given byte count.
$size: A size expressed as a number of bytes with optional SI or IEC binary unit prefix (e.g. 2, 3K, 5MB, 10G, 6GiB, 8 bytes, 9mbytes).
An integer representation of the size in bytes.
function parse_size($size) {
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
// Remove the non-unit characters from the size.
$size = preg_replace('/[^0-9\\.]/', '', $size);
// Remove the non-numeric characters from the size.
if ($unit) {
// Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by.
return round($size * pow(DRUPAL_KILOBYTE, stripos('bkmgtpezy', $unit[0])));
}
else {
return round($size);
}
}