Home >Backend Development >PHP Tutorial >Code to generate a random string using php

Code to generate a random string using php

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-07-25 09:03:221004browse
  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. }
  12. ?>
复制代码


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