diff --git a/alphanumeric-generator.php b/alphanumeric-generator.php index a7126fa..43424b0 100644 --- a/alphanumeric-generator.php +++ b/alphanumeric-generator.php @@ -1,19 +1,40 @@ ERROR: Sorry but the key_type ('.$key_type.') you are trying to use does not exist in unique_sequential_alphanumeric_generator().'); +} + + // Array character set + $chars = $key_array_range; + // Turn key string to array + $code_array = str_split($key_value); -function anderson_makiyama_get_next_alphanumeric($code){ - - $chars = str_split("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); - - $code_array = str_split($code); - - //Inicia uma busca pelo próximo caractere passível de incremento, ou seja, diferente de Z - //Note que inicia do último caractere para o primeiro + // Starts searching for the next character capable of increasing, or different from end of array + // Note that initiates the last character to the first for($i = count($code_array)-1;$i>-1;$i--){ - - if($code_array[$i] == "Z"){ + if($code_array[$i] == end($chars)){ if($i==0){ - //Se for igual a Z e for o primeiro caractere, então aumenta o comprimento e zera + // If equal to end of array and is the first character, mental increases the length and zeroes $code_array = array_fill(0,count($code_array) + 1,0); @@ -22,15 +43,16 @@ function anderson_makiyama_get_next_alphanumeric($code){ }else{ - if($code_array[$i -1] != 'Z'){ - //Se o caractere anterior for diferente de Z, incrementa-o e zera o atual e os subsequentes - //Se o caractere anterior for o primeiro, também funciona, pois incrementa ele e zera os demais + if($code_array[$i -1] != end($chars)){ + + // If the character is different from previous end of array, increment it and resets the current and subsequent + // If the character is above the first, also works because it increases and the other resets $code_array[$i -1] = $chars[array_search($code_array[$i -1],$chars) + 1]; for($j = $i; $j < count($code_array); $j++){ - $code_array[$j] = 0; + $code_array[$j] = reset($chars); } @@ -41,7 +63,7 @@ function anderson_makiyama_get_next_alphanumeric($code){ } }else{ - //calcula o próximo caractere, ou seja, incrementa o atual + // Calculate the next character, or increments the current $code_array[$i] = $chars[array_search($code_array[$i],$chars) + 1]; @@ -64,19 +86,4 @@ function anderson_makiyama_get_next_alphanumeric($code){ } } - ?> - - - - - - - - - - - - - - diff --git a/examplo.php b/examplo.php index 67faa9f..0d583c0 100644 --- a/examplo.php +++ b/examplo.php @@ -5,7 +5,7 @@ $current_number = "aZ5sTp53x"; // Get Next Number -$next_number = anderson_makiyama_get_next_alphanumeric($current_number); +$next_number = unique_sequential_alphanumeric_generator($current_number); echo "Current = " . $current_number; echo "Next = " . $next_number; @@ -20,11 +20,11 @@ for($i=0;$i<5000;$i++){ - $code = anderson_makiyama_get_next_alphanumeric($code); + $code = unique_sequential_alphanumeric_generator($code); echo $code; echo "
"; } -?> \ No newline at end of file +?> diff --git a/readme.md b/readme.md index b050247..2626bf1 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ -Sequential Alphanumeric Generator (v.0.1) +Unique Sequential Alphanumeric Generator (v.0.2) -Want to develope a url shortener or just obtain sequential alphanumeric strings, so this php function will help you. +Want to develope a url shortener or just obtain sequential alphanumeric strings for user passwords, so this php function will help you. This repository contains the open source Sequential Alphanumeric Generator that allows you to get the next alphanumeric number passing any alphanumeric number as parameter. @@ -20,10 +20,10 @@ have is: $current_number = "aZ5sTp53x"; // Get Next Number - $next_number = anderson_makiyama_get_next_alphanumeric($current_number); + $next_number = unique_sequential_alphanumeric_generator($current_number); +echo $next_number; - -[examples]: https://github.com/admiyn/sequential-alphanumeric-generator/blob/master/examplo.php +[examples]: https://github.com/LukasStribrny/unique_sequential_alphanumeric_generator/edit/patch-1/examplo.php