Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Odd Array

  1. #1
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts

    Odd Array

    Ok, I need a script that takes an string of characters, changes it, adds it to an array, and then echoes it.

    I can't do it in Javascript, because I don't want the users to see how it's done.

    So here are some possible ways of doing it:

    1. Is to have the button, and input field for the string. User inputs their string, clicks the button. PHP takes it, changes it a set number of times, and outputs every result on the new page.
    PHP Code:
    while($setnumberoftimes <= $numberoftimes)){ echo $result "/n" 
    I figured something like that would be my best bet?

    2. A database. I'd rather not take this route, but I do admit its possibility.

    3. Last but not least, if it won't happen, I can go back to doing javascript. Lol. It has to be hidden from the users though, I don't want them seeing the technique which I use to create the multiple strings.


    This really shouldn't stump me, as I know it's super easy to do =/.

  • #2
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    PHP Code:
    <?php

    $string 
    "abcde";

    $chars    strlen($string);

    $string_array = array();
    $i 0;
    while (
    $i $chars) {
        
    $string_array[$i]=$string[$i];
        
    $i++;
    }
    print_r ($string_array);


    ?>
    zomething likez thiz?

  • #3
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts
    Er, that works, somewhat, but I still need a lot of stuff added to it. I rarely work with arrays, but this would seem like the best way to do it?

    So say I have this:

    PHP Code:
    <?php

    function createRandomPassword() {



        
    $chars "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";

        
    srand((double)microtime()*1000000);

        
    $i 0;

        
    $pass '' ;



        while (
    $i <= 7) {

            
    $num rand() % 33;

            
    $tmp substr($chars$num1);

            
    $pass $pass $tmp;

            
    $i++;

        }



        return 
    $pass;



    }



    // Usage
    for ( $counter 10$counter <= 100$counter += 10) {
    $password createRandomPassword();
    }
    do {
    echo 
    "Your random password is: " $password "<br />";
    }
    while(
    $counter 10$counter <= 100$counter += 10)
    $ip=$_SERVER['REMOTE_ADDR']; 
    $File $ip ".txt";
    $Handle fopen($File'w+');
    $Data $password
    fwrite
    ($Handle$Data);
    print 
    "Data Written";
    fclose($Handle);


    ?>


    How would I make it work?


    It's on refresh right now. I'd just change the values and such to be variables, and add user input, but that part is easy.

  • #4
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    Sorry, but i don't follow

  • #5
    Regular Coder Deacon Frost's Avatar
    Join Date
    Feb 2008
    Location
    Between the Lines
    Posts
    279
    Thanks
    31
    Thanked 4 Times in 4 Posts
    I've got it basically working ^.^. I just have to add functionality.


    I made it so it writes to a file, and goes by IP address. I'll probably end up using a database... but..

    http://ispikedthepunch.com/emailgen/emails.php just so you understand ^.^.

  • #6
    Regular Coder funnymoney's Avatar
    Join Date
    Aug 2007
    Posts
    364
    Thanks
    17
    Thanked 24 Times in 24 Posts
    ok mate, glad you made it


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •