当前位置:Gxlcms > PHP教程 > PHP生成一个随机字符串

PHP生成一个随机字符串

时间:2021-07-01 10:21:17 帮助过:50人阅读

如果不需要可阅读的字符串,使用此函数替代,即可创建一个随机字符串,作为用户的随机密码等。

  1. /*************
  2. *@l - length of random string
  3. */
  4. function generate_rand($l){
  5. $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
  6. srand((double)microtime()*1000000);
  7. for($i=0; $i<$l; $i++) {
  8. $rand.= $c[rand()%strlen($c)];
  9. }
  10. return $rand;
  11. }

人气教程排行