To generate 6,8,10,16 digit unique random alphanumeric in PHP; this tutorial, i am going to show you how to generate 6,8,10,16 digit random, unique, alphanumeric string in PHP using str_shuffle() and md5() .
Generating unique random alphanumeric in Php is a very simple and easy task. And you can generate 6,8,10,16,20, etc digit unique random alphanumeric string in PHP. So for this, first of all you need to know the 2 inbuilt functions str_shuffle() and md5() of PHP.
- str_shuffle() :- The str_shuffle() function randomly shuffles all the characters of a string.
- md5() :- The md5() function calculates the MD5 hash of a string.
Generate 6,8,10,16 digit random unique Alphanumeric string in PHP
Use the following methods to generate 6,8,10,16 digit random unique Alphanumeric string in PHP:
- Generate 6, 10 Random Alphanumeric String Using str_shuffle() function
- Generate 8,10 Random Alphanumeric String Using md5 () function
Generate 6, 10 Random Alphanumeric String Using str_shuffle() function
Now, i will show you how to generate 6 digit unique random alphanumeric string in PHP using str_shuffle() function:
<?php $length = 6; $str = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz'; echo substr(str_shuffle($str), 0, $length); ?>
Result of the above code is:
HxJl2r
Now, i will show you how to generate 10 digit unique random alphanumeric string in PHP using str_shuffle() function:
<?php $length = 10; $str = '1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcefghijklmnopqrstuvwxyz'; echo substr(str_shuffle($str), 0, $length); ?>
Result of the above code is:
G8ckJ1x3VE
Generate 8, 10 Random Alphanumeric String Using md5() Function:
Now, i will show you how to generate 8,10 digit unique random alphanumeric string in PHP using md5() function:
<?php echo substr(md5(microtime()), 0, 10); echo "<br>"; echo substr(md5(microtime()), 0, 8); ?>
Result of the above code is:
5fa44a2bbc b1c7c213