parse_size

  1. drupal
    1. drupal6
    2. drupal7
Versionen
drupal6 – drupal7 parse_size($size)

Parse a given byte count.

Übergabeparameter

$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).

Rückgabewert

An integer representation of the size in bytes.

Verwandte Themen

▾ 6 functions call parse_size()

color_scheme_form_submit in modules/color/color.module
Submit handler for color change form.
CommonSizeTestCase::testCommonParseSize in modules/simpletest/tests/common.test
Check that parse_size() returns the proper byte sizes.
CommonSizeTestCase::testCommonParseSizeFormatSize in modules/simpletest/tests/common.test
Cross-test parse_size() and format_size().
file_upload_max_size in includes/file.inc
Determine the maximum file upload size by querying the PHP settings.
system_requirements in modules/system/system.install
Test and report Drupal installation requirements.
UploadTestCase::testLimit in modules/upload/upload.test
Attempt to upload a file that is larger than the maxsize and see that it fails.

Code

includes/common.inc, line 1724

<?php
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);
  }
}
?>

Kommentare

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen

Kommentar hinzufügen

Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angezeigt.
  • Internet- und E-Mail-Adressen werden automatisch umgewandelt.
  • Zulässige HTML-Tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Zeilen und Absätze werden automatisch erzeugt.

Weitere Informationen über Formatierungsoptionen