生成随机字符串,包含大写、小写字母、数字php代码

  1. function randstr($length) {
  2. $hash = '';
  3. $chars = 'abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz';
  4. $max = strlen($chars) - 1;
  5. mt_srand((double)microtime() * 1000000);
  6. for($i = 0; $i < $length; $i++) {
  7. $hash .= $chars[mt_rand(0, $max)];
  8. }
  9. return $hash;
  10. }