Home > php教程 > php手册 > 产生任意长度的字符串+数字随机数

产生任意长度的字符串+数字随机数

WBOY
Release: 2016-06-21 08:55:46
Original
1061 people have browsed it

   可以自定义产生什么字符串以及多长

     [PHP]代码

  function random($length)

  {

  $hash = '';

  $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';

  $max = strlen($chars) - 1;

  mt_srand((double)microtime() * 1000000);

  for($i = 0; $i

  {

  $hash .= $chars[mt_rand(0, $max)];

  }

  return $hash;

  }




Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template