How to generate random alphanumeric string in PHP?
In this post we will give you information about How to generate random alphanumeric string in PHP?. Hear we will give you detail about How to generate random alphanumeric string in PHP?And how to use it also give you demo for it if it is necessary.
In this example i am going to show you how to generate randomly alphanumeric string OR number in PHP. when you need you generate random alphanumeric string for your unique field then you can easily create using substr(), md5(), rand(), uniqid(), mt_rand(), time() and str_shuffle() php function you can create several way unique code using following example:
Example
Example 1
$generated = substr(md5(rand()),0,5);
print_r($generated);
Example 2
$generated = rand(10000,99999);
print_r($generated);
Example 3
$generated = substr(md5(uniqid(rand(), true)),0,5);
print_r($generated);
Example 4
$generated = substr(time(),5);
print_r($generated);
Example 5
$generated = substr(str_shuffle(md5(time())),0,5);
print_r($generated);
Example 6
$generated = substr( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ,mt_rand( 0 ,50 ) ,2 ) .substr( md5( time() ), 1,3);
print_r($generated);
Hope this code and post will helped you for implement How to generate random alphanumeric string in PHP?. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs