Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 4 of 4
  1. #1
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    I thought there might be some people interested in displaying random quotes on their
    web pages, in this case, random bumper-stickers. Just for the fun of it.

    This PHP script will be called: "bumper_sticker.php" and saved in the same directory as
    the attached text file (which contains all of the quotes ... see attached file).

    PHP Code:
    <?php
    #Read Bumper Sticker File
    $filename="bumper_sticker.txt";
    $lines = array();
    $fp fopen($filename"r");
    $array1 explode("\n"fread($fpfilesize($filename)));
    fclose ($fp);
    srand(time());
    $x mt_rand(1,count($array1));
    echo 
    "<span style='font-family: helvetica; font-size: 9pt; color: #000000;'>".$array1[$x-1]."</span>";
    ?>

    Then, inside any of your .php pages, use this line to display a random quote:

    <?php include("bumper_sticker.php");?>



    .


  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    PHP Code:
    $fp fopen($filename"r"); 
    $array1 explode("\n"fread($fpfilesize($filename))); 
    fclose ($fp); 
    Look at [phpfunction]file[/phpfunction].
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,715
    Member #
    5580
    Liked
    717 times
    filburt ...

    doh! I guess that is easier than my method.
    .... and someone will probably find a shorter way?

    That's what is so great about forum. Novice PHP programmers (like myself)
    can constantly learn better practices to accomplish tasks.

    Here's the new version:

    PHP Code:
    <?php
    #Random Bumper Sticker Generator
    $lines file("bumper_sticker.txt");
    srand(time());
    $x mt_rand(1,count($lines));
    echo 
    "<span style='font-family: helvetica; font-size: 9pt; color: #000000;'>".$lines[$x-1]."</span>";
    ?>

    .


  5. #4
    ljm
    ljm is offline
    Senior Member ljm's Avatar
    Join Date
    Aug 2006
    Location
    Manchester, England
    Posts
    284
    Member #
    13684
    Liked
    1 times
    Oooh that's good, thanks.

    I have an idea and will see how I can adapt that.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 04:53 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com