How to generate a small set of alphanumeric characters in PHP? [duplicate]

-3

How to generate a small character set in PHP, like this M7kL8a8z7q ?

I want to upload a lot of documents and want to rename the files in PHP as the image button does here in Stack Overflow. If I mix md5, with the date and others gets huge.

You do not need to follow this order of characters, just have to be random, do not repeat and have 10 characters.     

asked by anonymous 16.11.2017 / 20:00

1 answer

0

A simple password generator, you can change the password size by changing the length variable, and the possible characters by changing the characters variable. Font

function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}
    
16.11.2017 / 20:15