Press "Enter" to skip to content

php随机生成字符串

分享一下PHP随机生成字符串,以便以后使用时拿出来。

function random($length)
{
$hash = '';
$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_abcdefghijklmnopqrstuvwxyz';
$max = strlen($chars) - 1;
mt_srand((double)microtime() * 1000000);
$chr_len = rand(3,$length);
for($i = 0; $i < $chr_len; $i++)
{
$hash .= $chars[mt_rand(0, $max)];
}
 return $hash;
}
发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注