lundi 28 mars 2016

How to generate unique alpha-numeric string in php at time(with predefine length [length = 6])

I'm trying to generate 6 character long alpha numeric string in php.

I'm getting question and answers on stackoverflow.

shorturl on stackoverflow

Random string generate in php but not unique string

Random, unique string generate in php but didn't unique at time with 6 length of string

Can I generate more 1 Lacs string at time,

$arr = [];
$matchStr = [];
for($i=1;$i<=10000;$i++){
    $saltString = "ap_";
    $dynamicStr = substr(md5($saltString.$i), 26, 32);
    do{
       $arr[$i] = $dynamicStr;
    }while(!in_array($dynamicStr,$arr));
}

I'm generate strings possible to all ways but didn't get unique string and store into mysql table with unique index of column.

I know possibility of generate of string is:

$str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';

Random String Possibility: length of string: 10

a-z = 26

A-Z = 26

0-9 = 10

(26+26+10)^10 = 8.3929937 x 10^17 possibility at time.

is that any solution for generate string at time?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1SgbLui
via IFTTT

Aucun commentaire:

Enregistrer un commentaire