<?php
function getRandomString($len, $chars=null)
{
if (is_null($chars)){
$chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
mt_srand(10000000*(double)microtime());
for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
$str .= $chars[mt_rand(0, $lc)];
}
return $str;
}
echo getRandomString(8);
?>
生成随机 8 位数“英文+数字”字符
最新推荐文章于 2024-07-06 09:40:17 发布
本文介绍了一个使用PHP编写的简单实用的随机字符串生成函数。该函数可以指定生成字符串的长度及字符集,适用于多种需要随机字符串的应用场景。

5640

被折叠的 条评论
为什么被折叠?



