WireNumberTools::bytesToStr() method

Given a quantity of bytes (int), return readable string that refers to quantity in bytes, kB, MB, GB and TB

Available since version 3.0.214. All versions can also use the wireBytesStr() function

Usage

// basic usage
$string = $wireNumberTools->bytesToStr($bytes);

// usage with all arguments
$string = $wireNumberTools->bytesToStr($bytes, $options = []);

Arguments

NameType(s)Description
bytesint, string

Quantity in bytes (int) or any string accepted by strToBytes method.

options (optional)array, int

Options to modify default behavior, or if an integer then decimals option is assumed:

  • decimals (int|null): Number of decimals to use in returned value or NULL for auto (default=null). When null (auto) a decimal value of 1 is used when appropriate, for megabytes and higher (3.0.214+).
  • decimal_point (string|null): Decimal point character, or null to detect from locale (default=null).
  • thousands_sep (string|null): Thousands separator, or null to detect from locale (default=null).
  • small (bool|int): Make returned string as small as possible? false=no, true=yes, 1=yes with space (default=false)
  • labels (array): Labels to use for units, indexed by: b, byte, bytes, k, m, g, t
  • type (string): To force return value as specific type, specify one of: bytes, kilobytes, megabytes, gigabytes, terabytes; or just: b, k, m, g, t. (3.0.148+ only, terabytes 3.0.214+).

Return value

string


WireNumberTools methods and properties

API reference based on ProcessWire core version 3.0.248

Latest news

  • ProcessWire Weekly #581
    The 581st issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 28 June 2025
  • New ProcessWire admin redesign
    When you upgrade to ProcessWire 3.0.248 or newer (currently the dev branch), you’ll immediately notice something new and beautiful…
    Blog / 9 May 2025
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK