Format bytes with PHP – B, KB, MB, GB, TB, PB, EB, ZB, YB converter - Comment Page: 1
Simple PHP function that formats the bytes to the desired form. Possible unit options are:
Byte (B)
Kilobyte (KB)
Megabyte (MB)
Gigabyte (GB)
Terabyte (TB)
Petabyte (PB)
Exabyte (EB)
Zettabyte (ZB)
Yottabyte (YB)
Function takes three parameter: (bytes mandatory, unit optional, decimals optional)
[inttf_post_ad1]
PHP byteFormat function for formatting bytes
<?php
function byteFormat($bytes, $unit = "", $decimals = 2) {
$units = array('B' => 0, 'KB' => 1, 'MB' => 2, 'GB' => 3, 'TB' => 4,
'PB' => 5, 'EB' => 6, 'ZB' => 7, 'YB' => 8);
$value = 0;
if ($bytes > 0) {
// Generate automatic prefix by bytes
// If wrong prefix...
[…] "n"; echo byteFormat(1099511627776, "PB", 6) . "n";Kaynak: if-not-true-then-false.com Düzenleme için Umut‘a teÅŸekkürler. Benzer YazılarPHP – Resim üzerine yazı yazma […]
Raaaddddd!
Thanks dude. Saved me a bunch of time.
I used this for formating bytes, btw:
/**
* filesize function.
*
* @access public
* @static
* @param mixed $size
* @param int $round. (default: 0)
* @return void
*/
// http://www.veign.com/code-view.php?type=web&codeid=74
public static function filesize($size, $round = 0) {
$sizes = array(‘b’, ‘kb’, ‘meg’, ‘gb’, ‘tb’, ‘pb’, ‘eb’, ‘zb’, ‘yb’);
for ($i=0; $size > 1024 && isset($sizes[$i+1]); $i++) $size /= 1024;
return round($size, $round).$sizes[$i];
}
Thanks.
Dr Garg? How strange that I should find your name on a random website. I guess we were both looking for the same kind of info. :)
not much helpful…..
Amazing!!, but in the examples, consider remove the \n concat, because the example becomes difficult to read… greetings from Argentina.
Hi Juan,
Thanks, I removed \n from examples and yes, you are right, it’s easier to read.
Thanks man, very helpful function, i implemented it in my template engine.
Thanks again
Thanks, I owe you one.
nice
thanx sir for hlp me
Thanks sir…
Nice, Superb…
thanks, It helps a lot of !
Thanks man, very helpful function, i implemented it in my template engine.
Thanks again
Must explain.
Awesome speed