PHP code example of componenta / byte

1. Go to this page and download the library: Download componenta/byte 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/ */

    

componenta / byte example snippets


use Componenta\Stdlib\Byte;

$size = Byte::mb(1.5);

(string) $size;        // "1.5 MB"
$size->toBits();       // 12582912.0
$size->to('kB', 2);    // formatted string
$size->getValue('MB'); // numeric value in megabytes

$a = Byte::fromHumanReadable('10 MB');
$b = Byte::fromBits(8_000);
$c = Byte::from(2, 'GB');

use Componenta\Stdlib\BitRate;
use Componenta\Stdlib\Byte;

$rate = BitRate::mbps(80);

$seconds = Byte::mb(10)->getTransferTime($rate);
$amount = $rate->calculateTransferAmount(1);

BitRate::fromHumanReadable('80 Mbps');
BitRate::fromHumanReadable('10 MBps');
BitRate::kilobytesPerSecond(512);