Generate 8 Digit Alpha Numeric Unique Random String Using PHP, Generate Six Digit Unique Random String Using PHP, 8 Digit Random String Generete with php, Generate Unique Random String in PHP with Example
PHP Code: PHP Generate Unique Random Alphanumeric String
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <?php function getRandomString($digits) { $total_characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $randomString = ''; for ($i = 0; $i < $digits; $i++) { $index = rand(0, strlen($total_characters) - 1); $randomString .= $total_characters[$index]; } return $randomString; } echo getRandomString(8); ?> |
Alternative:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php $sixdigit=6; function getRandomString($digits) { $charset = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; $rand_str = ''; while(strlen($rand_str) < $digits) $rand_str .= substr(str_shuffle($charset), 0, 1); return $rand_str; } echo getRandomString(8); ?> |
You have been told well above through the code of php. How to get alpha variable in a variable by telling a unique random string of 8 digits. You copy this code and save it in your file. You can try running it on your server.