php 生成随机字符串

    /**
     * 获取随机字符串
     * @param $lenth
     * @return string
     */
    function getRandStr($lenth = 20)
    {     
        $strData = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
        $randString = '';
        $max = strlen($strData) - 1;
        for($i = 1;$i <= $lenth;$i ++)
        {
            $n = rand(0,$max) ;
            $randString .= substr($strData, $n,1);
        }     
        return $randString;
    }

posted @ 2017-10-19 11:46  没事就更  阅读(118)  评论(0编辑  收藏  举报