Return to Snippet

Revision: 40109
at January 26, 2011 07:54 by kentandre


Initial Code
function str_makerand($length, $useupper, $usespecial, $usenumbers) {
    $charset = "abcdefghijklmnopqrstuvwxyz";
    if ($useupper)
        $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    if ($usenumbers)
        $charset .= "0123456789";
    if ($usespecial)
        $charset .= "~@#$%^*()_+-={}|]["; // Note: using all special characters this reads: "~!@#$%^&*()_+`-={}|\\]?[\":;'><,./";
    if ($length == '' || $length == 0)
        $length = mt_rand(10, 40);
    for ($i = 0; $i < $length; $i++)
        $key .= $charset[(mt_rand(0, (strlen($charset) - 1)))];
    return $key;
}

Initial URL

                                

Initial Description

                                

Initial Title
Random string generator

Initial Tags

                                

Initial Language
PHP