AndieB Posted October 29, 2007 Share Posted October 29, 2007 Hi all gurus! I am off trying to see if I can create a ticket reservation system, where a visitor should be able to reserve tickets and get a randomized unique alphanumeric string in uppercase letters with a total of 8 characters. I do not know how to create a script that randomizes letters, from A-Z, and puts it into a string only 8 characters long. To compare it with already stored "randomized" in a database, I guess it is only to do a search in the database. Anyone who has a good advice or script on how to generate what I would like to achieve? Example: GUTIIKLE YYTESVOP PUERBHGA I guess you all know what I am after. Thankful for any kind of help! Sincerely, Andreas Quote Link to comment Share on other sites More sharing options...
micah1701 Posted October 29, 2007 Share Posted October 29, 2007 first make an array of all the letters/numbers you want to use. (if people will be typeing this string at somepoint I like to leave out the letter O and the number zero as well as the number 1 and letters like I and lowercase L) then do a loop with 8 passes. each time through the loop use rand() to pick a character out of your array and ad it to a string. Quote Link to comment Share on other sites More sharing options...
effigy Posted October 29, 2007 Share Posted October 29, 2007 <pre> <?php srand(time()); $pool = array_merge( range('a', 'z'), range('A', 'Z'), range(0, 9) ); $pool_size = count($pool) - 1; for ($i = 0; $i < 8; $i++) { echo $pool[rand(0, $pool_size)]; } ?> </pre> Quote Link to comment Share on other sites More sharing options...
AndieB Posted April 28, 2008 Author Share Posted April 28, 2008 <pre> <?php srand(time()); $pool = array_merge( range('a', 'z'), range('A', 'Z'), range(0, 9) ); $pool_size = count($pool) - 1; for ($i = 0; $i < 8; $i++) { echo $pool[rand(0, $pool_size)]; } ?> </pre> Thank you very much!! This solved it! 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.