在平时开发中会用到随机生成授权码,生成账户信息,生成密码,都需要随机字符串的生成,接下来上代码。
function generateRandomString($length = 6) {
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
echo generateRandomString(6);
本文链接:https://cloud.tencent.com/developer/article/1558647
本文采用CC BY-NC-SA 3.0 Unported协议进行许可,转载请保留此文章链接