+ -
当前位置:首页 → 问答吧 → 请教一个返回随机字符串的函数

请教一个返回随机字符串的函数

时间: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;
}

作者: qaz8555   发布时间: 2011-08-24

绿色部分去掉容易搞错的几个字符

作者: zhanyuzai   发布时间: 2011-08-24

热门下载

更多