From a06c0adde7b789323f76bf1695dc09f7a58a6f1a Mon Sep 17 00:00:00 2001 From: Lukas Stribrny Date: Mon, 24 Nov 2014 04:23:36 +0000 Subject: [PATCH 1/5] Function corrected Correction made in : line 11 : if($code_array[$i] == "Z") changed to if($code_array[$i] == end($chars)) line 23 : if($code_array[$i -1] != 'Z') changed to if($code_array[$i -1] != end($chars)) line 32 : $code_array[$j] = 0; changed to $code_array[$j] = reset($chars); Because it detect last and first character/value in array The generation was wrong. For example when it should generate string BA, the function generated B0 instead. Anyway the function is now working correctly. --- alphanumeric-generator.php | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/alphanumeric-generator.php b/alphanumeric-generator.php index a7126fa..31eedb7 100644 --- a/alphanumeric-generator.php +++ b/alphanumeric-generator.php @@ -1,19 +1,17 @@ -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 +20,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 +40,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,7 +63,6 @@ function anderson_makiyama_get_next_alphanumeric($code){ } } - ?> From 7bf99ddee5f9c396e3e805fbb9e4388c44b5a091 Mon Sep 17 00:00:00 2001 From: Lukas Stribrny Date: Mon, 24 Nov 2014 05:03:54 +0000 Subject: [PATCH 2/5] Update alphanumeric-generator.php I have put more option to choose from key types. --- alphanumeric-generator.php | 47 +++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/alphanumeric-generator.php b/alphanumeric-generator.php index 31eedb7..43424b0 100644 --- a/alphanumeric-generator.php +++ b/alphanumeric-generator.php @@ -1,9 +1,32 @@ 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); // Starts searching for the next character capable of increasing, or different from end of array // Note that initiates the last character to the first @@ -64,17 +87,3 @@ function anderson_makiyama_get_next_alphanumeric($code){ } ?> - - - - - - - - - - - - - - From 3f517e49bfb88aef3ac42da75f0af67f616abe07 Mon Sep 17 00:00:00 2001 From: Lukas Stribrny Date: Mon, 24 Nov 2014 05:09:58 +0000 Subject: [PATCH 3/5] Update examplo.php --- examplo.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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 +?> From f22e98e5df7ce06909c75d3cfa09afed2ed71fe4 Mon Sep 17 00:00:00 2001 From: Lukas Stribrny Date: Mon, 24 Nov 2014 05:12:10 +0000 Subject: [PATCH 4/5] Update readme.md --- readme.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index b050247..496dc1c 100644 --- a/readme.md +++ b/readme.md @@ -1,6 +1,6 @@ -Sequential Alphanumeric Generator (v.0.1) +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/sequential-alphanumeric-generator/blob/patch-1/examplo.php From 2eb100fe799c41b37db7fba8a54a1519cfd0dce1 Mon Sep 17 00:00:00 2001 From: Lukas Stribrny Date: Mon, 24 Nov 2014 05:34:52 +0000 Subject: [PATCH 5/5] Changed function name Sequential Alphanumeric Generator changed to Unique Sequential Alphanumeric Generator --- readme.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/readme.md b/readme.md index 496dc1c..2626bf1 100644 --- a/readme.md +++ b/readme.md @@ -1,4 +1,4 @@ -Sequential Alphanumeric Generator (v.0.2) +Unique Sequential Alphanumeric Generator (v.0.2) Want to develope a url shortener or just obtain sequential alphanumeric strings for user passwords, so this php function will help you. @@ -23,7 +23,7 @@ have is: $next_number = unique_sequential_alphanumeric_generator($current_number); echo $next_number; -[examples]: https://github.com/LukasStribrny/sequential-alphanumeric-generator/blob/patch-1/examplo.php +[examples]: https://github.com/LukasStribrny/unique_sequential_alphanumeric_generator/edit/patch-1/examplo.php