PHP code example of rych / bytesize
1. Go to this page and download the library: Download rych/bytesize library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
rych / bytesize example snippets
// Default formatter is metric (kilobyte = 1000 bytes)
$bytesize = new \Rych\ByteSize\ByteSize;
// Outputs 1.44MB
echo $bytesize->format(1440000);
// Use the binary formatter with a default precision of 1
$formatter = new \Rych\ByteSize\Formatter\Binary;
$formatter->setPrecision(1);
$bytesize = new \Rych\ByteSize\ByteSize($formatter);
// Outputs 1.4MiB
echo $bytesize->format(1509949);
use \Rych\ByteSize\ByteSize;
// Static methods also work in a pinch
echo ByteSize::formatMetric(1440000); // 1.44MB
echo ByteSize::formatBinary(1509949); // 1.44MiB