+ Reply to Thread
Results 1 to 3 of 3

Thread: PHP Word Scrambler - String Questions

  1. #1
    masterjake is offline x10Hosting Member masterjake is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    73

    Question PHP Word Scrambler - String Questions

    Hey guys,

    I'm making a php word scrambler and heres how it works.

    A person types all the words they want to scramble into a large textarea text field, separating each word by a comma, and then they press scramble. The php code splits each group of words between a set of commas into a seperate string and then scrambles the new word then converts the comma to a line break "<br>" so that when I display the results it seperates each scrambled word by a line. The only problem is I'm very lost as to how to do this. I know I will need the str_shuffle() function but can someone point out how to do the rest.

  2. #2
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: PHP Word Scrambler - String Questions

    assuming your form looks vaguely like the following:
    HTML Code:
    <form action='scramble.php' method='post'>
    <textarea name='words'></textarea>
    <input type='submit' value='Scramble!'>
    </form>
    then the following should work (I've included comments so you see what I'm doing and why, and hopefully you'll understand how it works ):
    scramble.php
    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
      <head>
      <title>Word Scrambler Results</title>
      <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'>
    </head>
    <body>
    <?php
    if (isset($_POST['words']))
      
    $words_s $_POST['words'];
    else
      die (
    'Give me a list of words, separated by a comma. <a href="http://forums.x10hosting.com/programming-help/index.html">Go back</a></body></html>');

    $words_s trim($words_s);
    // we don't want spaces or anything like that in the words, so we use trim to get rid of whitespace.
    $words_a explode(',',$words_s);
    // explode will convert a string into an array, with the first parameter being the delimiter.

    echo "<p>\n";
    foreach (
    $words_a as $word// foreach will iterate through the array, with each value being assigned to the variable $word.
      
    // this is what we do for each array value.
      
    $word str_shuffle($word); // str_shuffle simply reorders the characters in a string.
      
    echo "$word<br>\n";
      }

    ?><br>
    There are no more words left to scramble!</p>
    </body></html>
    Last edited by Scoochi2; 09-16-2008 at 06:48 AM.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  3. #3
    masterjake is offline x10Hosting Member masterjake is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    73

    Re: PHP Word Scrambler - String Questions

    Thank you very much this helped me so greatly.
    Edit:
    I have recoded the PHP Word Scrambler and put it online. If you have questions, suggestions, or comments, leave them here or send an e-mail to skateparkceasercash@yahoo.com. Below is the link to the word scrambler, enjoy!

    Word Scrambler: http://masterjake.x10hosting.com/word_scrambler/
    Last edited by masterjake; 09-17-2008 at 03:51 PM. Reason: Automerged Doublepost

+ Reply to Thread

Similar Threads

  1. tons of PHP Resources
    By Chris S in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-16-2009, 10:07 AM
  2. Problems with PHP?
    By Sup3rkirby in forum Free Hosting
    Replies: 4
    Last Post: 08-05-2008, 12:30 AM
  3. [PHP] PHP For Starters
    By Complex in forum Tutorials
    Replies: 24
    Last Post: 06-14-2008, 11:40 PM
  4. php vs html
    By conmark in forum Scripts & 3rd Party Apps
    Replies: 25
    Last Post: 07-12-2005, 02:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers