一个简单的php随机生成字符串函数
可以指定生成的字符串长度
{
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;
}
调用实例:
$randstr = rand_str(16);
您可能感兴趣的文章:
php生成指定位数(长度)的随机字符串
php生成随机产生六位数密码的代码
php生成随机数的例子
PHP批量更新数据库的示例代码
用PHP生成随机数的函数
php随机生成4位数字验证码
php生成随机数字和字母的实例代码
php生成随机字符串的函数
php生成N个不重复的随机数
php生成动态图片验证码的一段代码