How can I generate alphanumeric strings, log the last one created to file, and echo the string as a variable with PHP? I would want an output like: 0 1 2 3 .. 8 9 a b c d .. x y z 00 01 .. 08 09 0a 0b 0c 0d .. 0y 0z 10 11 12 .. 18 19 1a ...and so on. If anyone can show me how this is done, or even give me an hint me on how I could do it myself, It would be greatly appreciated! Thanks!
How would I integrate that with symbols like , .:;!)(/*-_ etc...? and is there a function that exists that can do this? I've read the PHP manual already and checked several place but was unable to find an answer. I'm a PHP noob...
Sorry I must have misunderstood your initial question, I assumed (following your example output) you wanting to use ranges. Can you ellaborate? - on what you mean by 'generate alphanumeric string', show an example?
I want to generate the sha256 hash keys for every possible letter/number/symbol combo possible up to 12 chars for logging to database. I have a lot of free CPU time . I want a script that generates these character combos in order with no duplicates and without using rainbow tables. The string is the character combo. Sorry for the misunderstanding.
It shouldn't be hard if you think of it logically. Since you want every possible letter/number/symbol, then I'd probably do it like this - the lazy way. Loops within loops - 12. Count for ASCII, exit one loop at the end of ASCII.. loop again for 11th element, same process, 10th element, etc etc. I'd help you develop a recursive function, but I'm too lazy right now.. lol
No idea if this will help your requirements, it will generate a random string not longer then 12 characters, if your going to store the string in db, just run a check if exists <html> <head></head> <body> <?php function genRandomString($length) { $characters = "~`!@#£€$¢¥$§%°^&*()-_+={}[]|\/§:;\"\'<>\,.?0123456789abcdefghijklmnopqrstuvwxyz"; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } echo genRandomString(12); // max length of characters ?> </body> </html> PHP:
Thanks for your help, but I need something that gives the strings in a sequential order as shown above. This way I have every string possible.
You should probably use base conversion of integers. for($i = 0; $i<100; $i++) echo base_convert($i,10,36),'<br/>'; PHP:
Heres something to play with, I wasn't able to run the first to strings, due to memory <?php //$phrase=" ~ ` ! @ # £ € $ ¢ ¥ $ § % ° ^ & * ( ) - _ + = { } [ ] | \ / § : ; \" ' < > , . ? 0 1 2 3 4 5 6 7 8 9 a b c d e f g h i j k l m n o p q r s t u v w x y z"; //$phrase=" ~ ` ! @ # £ € $ ¢ ¥ $ § % ° ^ & * ( ) - _ + = { } [ ] | \ / § : ; \" ' < > , . ?"; $phrase="0 1 2 3 4 5 6 7 8 9"; $string=explode(' ',$phrase); $string = string_array($string); function string_array($array) { $results = array(array( )); foreach ($array as $element) foreach ($results as $combo) array_push($results, array_merge(array($element), $combo)); echo '<pre>'; print_r($results); echo '</pre>'; } ?> PHP:
Run it and you'll see it. Its output is exactly the same as the output in your OP, check out the PHP.net manual for base_convert.
I ran it, and got no output. Just this error: Parse error: syntax error, unexpected T_STRING in /home2/altophon/public_html/test/strings.php on line 12. Any suggestions on getting this to work?