Home >Backend Development >PHP Tutorial >PHP generates random strings (customized pure numbers, pure letters or a mixture of numbers and letters)

PHP generates random strings (customized pure numbers, pure letters or a mixture of numbers and letters)

WBOY
WBOYOriginal
2016-07-25 08:53:261211browse
  1. //Generate a random string

  2. function rand_zifu($what,$number){
  3. $string='';
  4. for($i = 1; $i < ;= $number; $i++){
  5. //Mixed
  6. $panduan=1;
  7. if($what == 3){
  8. if(rand(1,2)==1){
  9. $what=1;
  10. }else{
  11. $what=2;
  12. }
  13. $panduan=2;
  14. }

  15. //Number

  16. if($what==1){
  17. $string.=rand(0 ,9);
  18. }elseif($what==2){
  19. //letter
  20. $rand=rand(0,24);
  21. $b='a';
  22. for($a =0;$a < =$rand;$a++){
  23. $b++;
  24. }
  25. $string.=$b;
  26. }
  27. if($panduan==2)$what=3;
  28. }
  29. return $string;
  30. }
  31. echo rand_zifu (3,10);

Copy code


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