1. Go to this page and download the library: Download bermudaphp/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/ */
bermudaphp / byte example snippets
use Bermuda\Stdlib\Byte;
// From numeric value (bytes)
$bytes = new Byte(1024);
// From string
$bytes = new Byte('1024 kB');
// Using static factory methods
$bytes = Byte::new(1024);
$bytes = Byte::kb(1024); // 1024 kilobytes
$bytes = Byte::mb(50); // 50 megabytes
$bytes = Byte::gb(2); // 2 gigabytes
// From human-readable string
$bytes = Byte::fromHumanReadable('2.5 GB');
// From bits
$bytes = Byte::fromBits(8192); // 1024 bytes
$bytes = new Byte(1536);
// Convert to human-readable string
echo $bytes->toString(); // "1.5 kB"
// Convert to specific units
echo $bytes->toKb(); // "1.5 kB"
echo $bytes->toMb(); // "0.0015 MB"
echo $bytes->toGb(); // "0.000001 GB"
// Customize format
echo $bytes->to('kb', 3, '_'); // "1.500_kB"
// Get raw value in specific unit
$kbValue = $bytes->getValue('kb'); // 1.5
use Bermuda\Stdlib\BitRate;
// From numeric value (bits per second)
$rate = new BitRate(1_000_000); // 1 Mbps
// Using static factory methods for bit-based rates
$rate = BitRate::bps(1000); // 1000 bits per second
$rate = BitRate::kbps(1000); // 1000 kilobits per second
$rate = BitRate::mbps(10); // 10 megabits per second
$rate = BitRate::gbps(1); // 1 gigabit per second
// Using static factory methods for byte-based rates
$rate = BitRate::bytesPerSec(125_000); // 125 KB/s (equivalent to 1 Mbps)
$rate = BitRate::kBps(1); // 1 kilobyte per second (8 kbps)
$rate = BitRate::mBps(1); // 1 megabyte per second (8 Mbps)
$rate = BitRate::gBps(1); // 1 gigabyte per second (8 Gbps)
// From any unit string
$rate = BitRate::from(10, 'Mbps'); // 10 Mbps
$rate = BitRate::from(1.5, 'GBps'); // 1.5 GB/s
// From human-readable string
$rate = BitRate::fromHumanReadable('10 Mbps');
$rate = BitRate::mbps(100); // 100 Mbps
// Get value in bits or bytes
$bitsPerSec = $rate->toBits(); // 100,000,000 bps
$bytesPerSec = $rate->toBytes(); // 12,500,000 B/s
// Convert to human-readable formats
echo $rate->toString(); // "100 Mbps"
echo $rate->toString('byte'); // "12.5 MBps"
// Convert to specific units
echo $rate->toMbps(); // "100 Mbps"
echo $rate->toGbps(); // "0.1 Gbps"
echo $rate->toMBps(); // "12.5 MBps"
echo $rate->toKBps(); // "12500 kBps"
// Customize output format
echo $rate->to('Mbps', 3, '_'); // "100.000_Mbps"
$rate = BitRate::mbps(100); // 100 Mbps
// Compare with another bit rate
$rate->equalTo(BitRate::kbps(100000)); // true
$rate->equalTo('100 Mbps'); // true
$rate->equalTo('12.5 MBps'); // true (bytes equivalent)
// Greater/less than comparisons
$rate->greaterThan(BitRate::mbps(50)); // true
$rate->lessThan(BitRate::gbps(1)); // true
// Compare with arrays
$rate->greaterThan(['10 Mbps', '150 Mbps'], BitRate::MODE_ANY); // true
use Bermuda\Stdlib\BitFormatter;
use Bermuda\Stdlib\Byte;
use Bermuda\Stdlib\BitRate;
// Load translation files
BitFormatter::loadLanguage('/path/to/translations/en.php');
BitFormatter::loadLanguage('/path/to/translations/fr.php');
BitFormatter::loadLanguage('/path/to/translations/ru.php');
// Or load all translations from a directory
BitFormatter::loadLanguagesFromDirectory('/path/to/translations');
/* The library comes with built-in translations for multiple languages. You can load all available translations at once using the `loadDefaults()` method*/
BitFormatter::loadDefaults()
// Format time in different languages
$fileSize = Byte::gb(2);
$downloadSpeed = BitRate::mbps(25);
$seconds = BitFormatter::calculateTransferTime($fileSize, $downloadSpeed);
echo BitFormatter::formatTime($seconds, 'en'); // "10 minutes, 40 seconds"
echo BitFormatter::formatTime($seconds, 'fr'); // "10 minutes et 40 secondes"
echo BitFormatter::formatTime($seconds, 'ru'); // "10 минут и 40 секунд"
// Set default language
BitFormatter::setDefaultLanguage('fr');
echo BitFormatter::formatTime($seconds); // "10 minutes et 40 secondes"
// Direct formatting with BitRate and Byte classes
echo $downloadSpeed->getFormattedTransferTime($fileSize, 'en'); // "10 minutes, 40 seconds"
echo $fileSize->getFormattedTransferTime($downloadSpeed, 'ru'); // "10 минут и 40 секунд"
// Format data values
echo BitFormatter::humanizeBytes(1536); // "1.5 kB"
echo BitFormatter::humanizeBitRate(1_000_000, 'bit'); // "1 Mbps"
echo BitFormatter::humanizeBitRate(1_000_000, 'byte'); // "125 kBps"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.