>  기사  >  백엔드 개발  >  php生成随机字符串(自定义纯数字、纯字母或数字字母混合)

php生成随机字符串(自定义纯数字、纯字母或数字字母混合)

WBOY
WBOY원래의
2016-07-25 08:53:261135검색
  1. //生成随机字符串

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

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


성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.