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 4 of 4
  1. #1
    New Coder
    Join Date
    Nov 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how to make random echos

    hi, i was wondering how i can use php to echo random phrases/quotes like

    'blah blah blah'
    'asldhasf kdjhfskjf hsjdhf'

    and so on.

    i did find something like this..
    PHP Code:
    <?
    //Chooses a random number
    $num Rand (1,6);
    //Based on the random number, gives a quote
    switch ($num)
    {
    case 
    1:
    echo 
    "Time is money";
    break;
    case 
    2:
    echo 
    "An apple a day keeps the doctor away";
    break;
    case 
    3:
    echo 
    "Elmo loves dorthy";
    break;
    case 
    4:
    echo 
    "Off to see the wizard";
    break;
    case 
    5:
    echo 
    "Tomorrow is another day";
    break;
    case 
    6:
    echo 
    "PHP is cool!";
    }
    ?>
    but for some reason, taht seems like it takes up too much space and too much time

    i want a very simple script that is minimal and still works
    Last edited by jl9148; 01-26-2007 at 06:15 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    You could build an array of strings and use that rand() function to display a random string from the array...

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Canada, eh?
    Posts
    133
    Thanks
    2
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Fumigator View Post
    You could build an array of strings and use that rand() function to display a random string from the array...
    And here's the code, jl, since it seems like you don't know much PHP:

    PHP Code:
    $meh = array("I like cheese.","...","...");
    echo 
    $meh[array_rand($meh)]; 
    Last edited by Eternity Angel; 01-27-2007 at 12:48 AM.
    Bored? Might as well play Fantasian Kingdoms: http://www.fantasiankingdoms.com/

    Check out my JavaScript Image Project: http://codingforums.com/showthread.php?t=185231

  • #4
    New Coder
    Join Date
    Nov 2006
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hehe thanks


  •  

    Posting Permissions

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