Alphanumeric form generator

1

I developed an alphanumeric generator routine, to be placed in a field of a form. However, it does not generate numbering. Can anyone help?

This field below:

<div class="guiaprest">
            <label name="tPrest"> 2- Nº Guia no Prestador</label>
        </div>

So I did some research on the internet, and I found a template and did so:

<?php
function rand_sem_num_repetido($qtd_numeros,$limite_min,$limite_max){
    for($i=0;$i<=$qtd_numeros;$i++){
        $aux=rand($limite_min,$limite_max);

        if($i>=1){
            while(in_array($aux,$index)){
                $aux=rand($limite_min,$limite_max);
            }
        }

        $index[$i]=$aux;
    }

    return $index;
}
?>
    
asked by anonymous 30.08.2016 / 20:56

1 answer

0
function rand_sem_num_repetido($qtd_numeros,$limite_min,$limite_max){
    $index = array();
    for($i=0;$i<$qtd_numeros;$i++){
       $aux=rand($limite_min,$limite_max);

       if($i>=1){
           while(in_array($aux,$index)){
               $aux=rand($limite_min,$limite_max);
           }
       }

       $index[$i]=$aux;
    }
    return implode($index);
}

Try this. But this function does not generate an alphanumeric, and this parameter of $qtd_numeros will not limit the number of characters can come 2 characters but 1 number. (E.g., 10 (Dec)). To limit the number of characters you can change the return to return substr(implode($index), 0, $qtd_numeros); or pass $limite_min = 0 and $limite_max = 9 .

    
30.08.2016 / 21:25