Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

Random String Generator (See related posts)

// Generate a random-length string

<?php
// Pass $size as a KB value - see the PHP filesize() function.
function fsformat ($size)
{
    if ($size < 1024)
    {
        return $size.'KB';
    }
    else if ($size >= 1024 && $size < 1048576)
    {
        return round(($size/1024), 0).'MB';
    }
    else if ($size >= 1048576 && $size < 1073741824)
    {
        return round(($size/1048576), 0).'GB';
    }
    else if ($size >= 1073741824 && $size < 1099511627776)
    {
        return round(($size/1073741824), 0).'TB';
    }
    else
    {
        return 'Error';
    }
}
?>

You need to create an account or log in to post comments to this site.


Related Posts