请教一个返回随机字符串的函数
时间:2011-08-24
来源:互联网
函数如下,绿色文字部分的意思是什么?只是把这些变量清除吗?是随意清除掉几个字符吗?还是有规律的行为?
function random_text($count, $rm_similar = false)
{
// create list of characters
$chars = array_flip(array_merge(range(0, 9), range('A', 'Z')));
// remove similar looking characters that might cause confusion
if ($rm_similar)
{
unset($chars[0], $chars[1], $chars[2], $chars[5], $chars[8],
$chars['B'], $chars['I'], $chars['O'], $chars['Q'],
$chars['S'], $chars['U'], $chars['V'], $chars['Z']);
}
// generate the string of random text
for ($i = 0, $text = ''; $i < $count; $i++)
{
$text .= array_rand($chars);
}
return $text;
}
function random_text($count, $rm_similar = false)
{
// create list of characters
$chars = array_flip(array_merge(range(0, 9), range('A', 'Z')));
// remove similar looking characters that might cause confusion
if ($rm_similar)
{
unset($chars[0], $chars[1], $chars[2], $chars[5], $chars[8],
$chars['B'], $chars['I'], $chars['O'], $chars['Q'],
$chars['S'], $chars['U'], $chars['V'], $chars['Z']);
}
// generate the string of random text
for ($i = 0, $text = ''; $i < $count; $i++)
{
$text .= array_rand($chars);
}
return $text;
}
作者: qaz8555 发布时间: 2011-08-24
绿色部分去掉容易搞错的几个字符
作者: zhanyuzai 发布时间: 2011-08-24
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28