PHP generate random alphanumeric string

To generate random alphanumeric string there are many ways to generate a random, unique, alphanumeric string in PHP. The following ways to generate random alphanumeric string

Using str_shuffle() Function: 

The str_shuffle() function is an inbuilt function in PHP and is used to randomly shuffle all the characters of a string passed to the function as a parameter. When a number is passed, it treats the number as the string and shuffles it. This function does not make any change in the original string or the number passed to it as a parameter. Instead, it returns a new string which is one of the possible permutations of the string passed to it in the parameter.


$length = 10;
$data = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz';

echo substr(str_shuffle($used_symbols), 0, $length);
echo "<br />";
echo substr(str_shuffle($used_symbols), 0, 8);


2 y fd5eIFrh

Using md5() Function:

The md5() function is used to calculate the MD5 hash of a string. Pass timestamp as a argument and md5 function will convert them into 32 bit characters

echo substr(md5(microtime()), 0, 10); 
echo substr(md5(microtime()), 0, 8); 

// output

Recommended Posts:


  1. AffiliateLabz said:

    Great content! Super high-quality! Keep it up! 🙂

    February 16, 2020
  2. Alexis said:

    I am really inspired with your writing skills and also with the format to your
    weblog. Is this a paid subject matter or did you customize it
    yourself? Anyway keep up the excellent quality writing, it is rare to peer a great weblog like this one nowadays..

    Feel free to surf to my web site cheap flights

    January 31, 2021
  3. Seth said:

    Ridiculous story there. What happened after? Take care!

    Also visit my web blog … cheap flights

    February 1, 2021
  4. Alta said:

    Asking questions are in fact nice thing if you are not understanding anything
    entirely, but this post provides nice understanding yet.

    Here is my site; cheap flights (

    February 2, 2021
  5. Zachary said:

    Fantastic site you have here but I was wanting to know if
    you knew of any forums that cover the same topics discussed in this article?

    I’d really like to be a part of community where I
    can get responses from other knowledgeable people that share the same
    interest. If you have any suggestions, please let me know.
    Bless you!

    Feel free to visit my web site cheap flights

    February 2, 2021
  6. Lauri said:

    With havin so much content and articles
    do you ever run into any problems of plagorism or copyright infringement?
    My site has a lot of exclusive content I’ve either written myself or outsourced
    but it seems a lot of it is popping it up all over the internet
    without my authorization. Do you know any solutions to help prevent content from being ripped off?
    I’d definitely appreciate it.

    Take a look at my web page: cheap flights (

    February 3, 2021
  7. Natalia said:

    Fantastic goods from you, man. I have take into account your stuff previous to
    and you are simply too magnificent. I really like what you have got right here, certainly like what you are stating and the best way during which you are saying it.
    You are making it enjoyable and you continue to take care of to stay it smart.
    I can’t wait to learn far more from you. This is really a terrific site.

    Here is my web blog: cheap flights (

    February 12, 2021
  8. Max said:

    Ebook Reader News Top Books 2019 Personal Development

    Also visit my web blog … pdf base

    February 16, 2021
  9. Venetta said:

    Handbook Of Chemistry And Physics Online Free Philippine Short Stories With Summary Pdf

    February 18, 2021

Leave a Reply

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