common.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkPHP [ WE CAN DO IT JUST THINK ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 流年 <liu21st@gmail.com>
  10. // +----------------------------------------------------------------------
  11. // 应用公共文件
  12. if (!function_exists('getNewRand'))
  13. {
  14. /**
  15. * 获取字母数字随机数
  16. * @param int $len
  17. * @return string
  18. * @author matielong
  19. */
  20. function getNewRand($len = 4)
  21. {
  22. $chars_array = array(
  23. "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
  24. "A", "B", "C", "D", "E", "F", "G",
  25. "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
  26. "S", "T", "U", "V", "W", "X", "Y", "Z",
  27. );
  28. $charsLen = count($chars_array) - 1;
  29. $outputstr = "";
  30. for ($i=0; $i<$len; $i++)
  31. {
  32. $outputstr .= $chars_array[mt_rand(0, $charsLen)];
  33. }
  34. return $outputstr;
  35. }
  36. }