Return to Snippet

Revision: 30860
at August 24, 2010 10:10 by Jamie


Initial Code
function abbr_number($size) {
    $size = preg_replace('/[^0-9]/','',$size);
    $sizes = array("", "K", "M");
    if ($size == 0) { return('n/a'); } else {
    return (round($size/pow(1000, ($i = floor(log($size, 1000)))), 0) . $sizes[$i]); }
}

function format_size($size) {
    $sizes = array(" Bytes", " KB", " MB", " GB", " TB", " PB", " EB", " ZB", " YB");
    if ($size == 0) { return('n/a'); } else {
    return (round($size/pow(1024, ($i = floor(log($size, 1024)))), $i > 1 ? 2 : 0) . $sizes[$i]); }
}

Initial URL
http://us3.php.net/manual/en/function.filesize.php#99333

Initial Description
A little restrictive, but should work for simple implementations. I\'m using this to replicate Facebook\'s \"35K people like this\" button format.\r\nThe original code is included below my modification.

Initial Title
Round Large Numbers to a Letter Abbreviation eg: 25,000 to 25K

Initial Tags

                                

Initial Language
PHP