Home  >  Article  >  Backend Development  >  PHP generates a random string

PHP generates a random string

巴扎黑
巴扎黑Original
2016-11-21 14:46:071422browse

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;
}


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn