Also sends a random string generation function

Source: Internet
Author: User
Also sends a random string generation function
<无详细内容>

  1. /**
  2. * Generate a random number
  3. *
  4. * @ Param int $ length: generate the string length
  5. * @ Param int $ type string type
  6. * @ Param bool $ special whether to use special characters
  7. * @ Return string returns the generated random string.
  8. * @ Example random (10, null, true );
  9. */
  10. Function random ($ length, $ type = NULL, $ special = FALSE ){
  11. $ Str = "";
  12. Switch ($ type ){
  13. Case 1:
  14. $ Str = "0123456789 ";
  15. Break;
  16. Case 2:
  17. $ Str = "abcdefghijklmnopqrstuvwxyz ";
  18. Break;
  19. Case 3:
  20. $ Str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
  21. Break;
  22. Case 4:
  23. $ Str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ";
  24. Break;
  25. Default:
  26. $ Str = "abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789 ";
  27. Break;
  28. }
  29. Return substr (str_shuffle ($ special! = FALSE )? '! @ # $ % ^ & * () _ + '. $ Str: $ str), 0, $ length );
  30. }

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.