PHP code example of ramazancetinkaya / byte-formatter
1. Go to this page and download the library: Download ramazancetinkaya/byte-formatter 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/ */
ramazancetinkaya / byte-formatter example snippets
use ramazancetinkaya\ByteFormatter;
$formatter = new ByteFormatter(true, 2); // Binary prefixes, 2 decimal places
echo $formatter->formatBytes(10240); // Output: "10 KiB"
use ramazancetinkaya\ByteFormatter;
$formatter = new ByteFormatter();
$bytes = $formatter->parseSize("1.5 MiB");
echo $bytes; // Output: 1572864
use ramazancetinkaya\ByteFormatter;
$formatter = new ByteFormatter();
echo $formatter->convert(10240, false); // Output: "10 KB" (Decimal prefix)