mercredi 16 mars 2016

PHP: Generate random Code excluding (0, 1, O and L)

I am trying to generate random voucher code applying the following rules:

Alphanumeric combination 5 characters in capital case (A-Z, 0-9, and take away 1, 0, I, O).

This is my try

<?php
function generateRandomString($length = 5) {
    return substr(str_shuffle("23456789ABCDEFGHIJKMNPQRSTUVWXYZ"), 0, $length);
}


echo generateRandomString();
?>

but i am not sure if there is a better way of doing this




Aucun commentaire:

Enregistrer un commentaire