您的位置:首页 > 编程语言 > PHP开发

php生成随机唯一邀请码/优惠码 固定长度

2016-11-17 11:08 579 查看
function make_coupon_card() {

    $code = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

    $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 ] ),

        $d .= $s[ ( $g ^ ord( $a[ $f + 8 ] ) ) - $g & 0x1F ],

        $f++

    );

    return $d;

}

echo make_coupon_card();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: