public static function Bytes::toInt in Zircon Profile 8
Same name and namespace in other branches
- 8.0 core/lib/Drupal/Component/Utility/Bytes.php \Drupal\Component\Utility\Bytes::toInt()
Parses a given byte size.
Parameters
mixed $size: An integer or string 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).
Return value
int An integer representation of the size in bytes.
8 calls to Bytes::toInt()
- BytesTest::testToInt in core/
tests/ Drupal/ Tests/ Component/ Utility/ BytesTest.php - Tests \Drupal\Component\Utility\Bytes::toInt().
- color_scheme_form_submit in core/
modules/ color/ color.module - Form submission handler for color_scheme_form().
- EditorImageDialog::buildForm in core/
modules/ editor/ src/ Form/ EditorImageDialog.php - Environment::checkMemoryLimit in core/
lib/ Drupal/ Component/ Utility/ Environment.php - Compares the memory required for an operation to the available memory.
- FileItem::getUploadValidators in core/
modules/ file/ src/ Plugin/ Field/ FieldType/ FileItem.php - Retrieves the upload validators for a file field.
File
- core/
lib/ Drupal/ Component/ Utility/ Bytes.php, line 32 - Contains \Drupal\Component\Utility\Bytes.
Class
- Bytes
- Provides helper methods for byte conversions.
Namespace
Drupal\Component\UtilityCode
public static function toInt($size) {
// Remove the non-unit characters from the size.
$unit = preg_replace('/[^bkmgtpezy]/i', '', $size);
// Remove the non-numeric characters from the size.
$size = preg_replace('/[^0-9\\.]/', '', $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(self::KILOBYTE, stripos('bkmgtpezy', $unit[0])));
}
else {
return round($size);
}
}