random-string-AZ09.php 803 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * dolphin. Collection of useful PHP skeletons.
  4. * Copyright (C) 2009 Johannes 'Banana' Keßler
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
  8. *
  9. * You should have received a copy of the
  10. * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
  11. * along with this program. If not, see http://www.sun.com/cddl/cddl.html
  12. */
  13. /**
  14. * create a random A-Z 0-9 string with the given length
  15. * @author banana mail@bananas-playground.net
  16. * @param string $lentgh Default 5
  17. * @return string The random string
  18. */
  19. function randomAZ09($length=5) {
  20. $str = '';
  21. for ($i=0; $i<$length; $i++) {
  22. $d = rand(1,30)%2;
  23. $str .= $d ? chr(rand(65,90)) : chr(rand(48,57));
  24. }
  25. return $str;
  26. }
  27. ?>