Results 1 to 8 of 8

Thread: Randomness

  1. #1

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702

    Randomness

    OK, I hope this is teh right forum.

    How can I randomly generate phrases?

    Now where would they generate from?

  2. #2

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    *bump the rump*

  3. #3
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    you want to create entirely random phrases, or randomly select a phrase?

    To Select a phrase:
    PHP Code:
    <?php

    /*
        Add this line of code in your page:
        <?php include "random_quote.php"; ?>
    */

    $quotes[] = "This is a quote";
    $quotes[] = "This is another";
    $quotes[] = "quote 3";
    $quotes[] = "quote 4";
    $quotes[] = "quote 5";
    $quotes[] = "quote 6";

    srand ((double) microtime() * 1000000);
    $randomquote rand(0,count($quotes)-1);

    echo 
    "<p>" $quotes[$randomquote] . "</p>";

    ?>

    -morrowasted

  4. #4
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629
    if you're even using PHP to do it.. use the rand() function.

    to generate phrases, set the phrases into an array and do this:

    PHP Code:
    <?
      $array = array("phrase1","phrase2","phrase3");
      $i = rand(0, (count($array) - 1));
      echo $array[$i];
    ?>
    there are a number of ways you can put the phrases into an array, like calling up a MySQL database or even just using a plain text file..
    Like Archer? Check out some Sterling Archer quotes.

  5. #5
    Lively Member morrowasted's Avatar
    Join Date
    Aug 2003
    Location
    Houston, TX
    Posts
    118
    hes is shorter, i stole mine from hotscripts... use his

    -morrowasted

  6. #6

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    The include function doesn't seem to show the random_quote.php on my server.

    http://www.sniffum.com/secret.html

    and

    http://www.sniffum.com/random_quote.php

    the random_quote.php should show up at the bottom of secret.html

    the only thing that worked for me was iframe's.

    That's my last resort. I have enough iFrame's.

  7. #7
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    You have to include it on a PHP page.


    PHP Code:
    include("random_quote.php"); 
    So make your secret.html => secret.php

  8. #8

    Thread Starter
    Fanatic Member duc's Avatar
    Join Date
    Oct 2002
    Location
    STEAM
    Posts
    702
    kick ass avatar , 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
  •  



Click Here to Expand Forum to Full Width