ansipants Posted November 8, 2012 Share Posted November 8, 2012 Ok, so I'm attempting to work on a script that will generate random codes and I also want to be able to change the multiplier with a form. Here is what I have so far: <code> <?php $chars = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Alpha numberic character $chars .= "123456789"; $chars .= "123456789"; $chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $chars .= "123456789"; $chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $chars .= "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $chars .= "123456789"; $chars .= "123456789"; $chars = str_shuffle($chars); $chars = substr($chars, 0, 15); /** This is the part I'm not sure how to do because it generates the same codes 5 times in a row and I want it to generate different codes on each line or maybe do a form that I can change the multiplier number to generate more */ $input = $chars; $multiplier = 5; $separator = "<br>\n"; print implode($separator, array_fill(0, $multiplier, $input)); print "<br>\n"; ?> </code> Sorry I'm a n00b and trying to learn more =) Quote Link to comment Share on other sites More sharing options...
requinix Posted November 8, 2012 Share Posted November 8, 2012 $input is the random string. You generated it a few lines before. All you do with it is repeat it $multiplier times. If you want a different random string each time then you have to repeat the part that generates it. Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 8, 2012 Share Posted November 8, 2012 <?php $letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; // Alpha characters $numbers = "123456789"; //Numeric characters $characters = str_repeat($letters, 4) . str_repeat($numbers, 9); $multiplier = 5; $length = 15; $separator = "<br>\n"; $codes = array(); for($i=0; $i<$multiplier; $i++) { $rand_chars = str_shuffle($characters); $codes[] = substr($rand_chars, 0, $length); } print implode($separator, $codes); print "<br>\n"; ?> Quote Link to comment Share on other sites More sharing options...
ansipants Posted November 8, 2012 Author Share Posted November 8, 2012 you're so awesome! ty Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.