Random string generator

function generate_string($length=10){
        $chars = array_merge(range(0, 9),  range('A', 'Z'), range('A', 'Z'));
        $string = implode(array_slice($chars, 0, $length));
        return $string;

3 thoughts on “Random string generator

  1. Hello Tahir,
    I think the third rang(‘A’, ‘Z’) should be rang(‘a’, ‘z’), otherwise, your generated string will contains no lower letters.

    • tahiryasin

      Yes, you are right but I intentionally capitalized, but you can change their case if you need both upper and lower case letters.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: