php生成唯一的八位英文+数字邀请码实现

 /**生成单个邀请码
     * @return string
     */
    public static  function make_invite_code(){
        $code="ABCDEFGHIGKLMNOPQRSTUVWXYZ";


        $rand=$code[rand(0,25)].strtoupper(dechex(date('m')))
            .date('d').substr(time(),-5)
            .substr(microtime(),2,5).sprintf('%02d',rand(0,99));
        for(
            $a = md5( $rand, true ),
            $s = '0123456789ABCDEFGHIJKLMNOPQRSTUV',
            $d = '',
            $f = 0;
            $f < 8;
            $g = ord( $a[ $f ] ), // ord()函数获取首字母的 的 ASCII值
            $d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ],  //按位亦或,按位与。
            $f++
        );
        return $d;
    }

猜你喜欢

转载自blog.csdn.net/zlb_lover/article/details/80446922
今日推荐