php随机生成数字加字母的字符串
function getRandomString($len, $chars=null)
{
if (is_null($chars)) {
$chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
}
mt_srand(10000000*(double)microtime());
for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++) {
$str .= $chars[mt_rand(0, $lc)];
}
return $str;
}
例如随机生成 6 位 字母和数字组合
只需调用函数 并传参6即可。
echo getRandomString(6);
本文来自博客园,作者:小ྀ青ྀ年້,转载请注明原文链接:https://www.cnblogs.com/dalaowang/p/11805407.html

浙公网安备 33010602011771号