Random String Generator

Below is a simple script to generate random string/password using PHP.

You can customize the same by adding special characters.

function randomPassword() {
    $alphabet = 
    $pass = array(); //remember to declare $pass as an array
    $alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
    for ($i = 0; $i < $len; $i++) {
        $n = rand(0, $alphaLength);
        $pass[] = strtoupper($alphabet[$n]);
    return implode($pass); //turn the array into a string

echo randomPassword($len); //length of the string

Hope this is helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to top