Home > Article > Backend Development > PHP generates a random string
If you do not need a readable string, use this function instead to create a random string as the user's random password, etc.
/************* *@l - length of random string */ function generate_rand($l){ $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; srand((double)microtime()*1000000); for($i=0; $i<$l; $i++) { $rand.= $c[rand()%strlen($c)]; } return $rand; }