1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How Do I Make A Sequential Alphanumeric String Generator?

Discussion in 'PHP' started by interwho, Aug 29, 2010.

  1. #1
    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!
     
    Last edited: Aug 29, 2010
    interwho, Aug 29, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    Look into to the range() function (a-z, 0-9) etc.
     
    danx10, Aug 29, 2010 IP
  3. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3
    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...
     
    Last edited: Aug 29, 2010
    interwho, Aug 29, 2010 IP
  4. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #4
    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?
     
    danx10, Aug 29, 2010 IP
  5. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #5
    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.
     
    interwho, Aug 29, 2010 IP
  6. xcool101Man

    xcool101Man Guest

    Messages:
    48
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    there has to be a library for generating the sha256 keys online
    try searching google for it
     
    xcool101Man, Aug 30, 2010 IP
  7. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #7
    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
     
    Rainulf, Aug 30, 2010 IP
  8. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #8
    The only library I found for generating strings used rainbow tables
     
    interwho, Aug 30, 2010 IP
  9. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #9
    Does anyone know how to do this?
     
    interwho, Aug 30, 2010 IP
  10. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #10
    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:
     
    MyVodaFone, Aug 30, 2010 IP
  11. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #11
    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.
     
    interwho, Aug 30, 2010 IP
  12. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #12
    You should probably use base conversion of integers.

    
    for($i = 0; $i<100; $i++)
        echo base_convert($i,10,36),'<br/>';
    
    PHP:
     
    Gray Fox, Aug 31, 2010 IP
  13. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #13

    How would that work?
     
    interwho, Sep 5, 2010 IP
  14. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #14
    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:
     
    MyVodaFone, Sep 5, 2010 IP
  15. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #15
    Question: What does that do? (Sorry!)
     
    interwho, Sep 5, 2010 IP
  16. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #16
    Your basically looking for all the possible combinations in a string ?
     
    MyVodaFone, Sep 5, 2010 IP
  17. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #17
    yes, i am.
     
    interwho, Sep 5, 2010 IP
  18. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #18
    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.
     
    Gray Fox, Sep 6, 2010 IP
  19. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #19
    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?
     
    Last edited: Sep 6, 2010
    interwho, Sep 6, 2010 IP
  20. interwho

    interwho Member

    Messages:
    198
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #20
    Does this just print all the results on one VERY long page?
     
    interwho, Sep 7, 2010 IP