PHP 生成随机字符串 - PHP 源码
php 代码
- function random_string($length, $max=FALSE)
- {
- if (is_int($max) && $max> $length)
- {
- $length = mt_rand($length, $max);
- }
- $output = '';
- for ($i=0; $i<$length; $i++)
- {
- $which = mt_rand(0,2);
- if ($which === 0)
- {
- $output .= mt_rand(0,9);
- }
- elseif ($which === 1)
- {
- $output .= chr(mt_rand(65,90));
- }
- else
- {
- $output .= chr(mt_rand(97,122));
- }
- }
- return $output;
- }
来源: https://www.php1.cn/detail/php-6b58d4ea66.html