Nov 21, 2009

Random Quote Script

free web hosting
Open Discussion > MODERATED AREA > Tutorials

Random Quote Script

Avalon
Here's a little random quote script that you can use to randomly choose from an array of quotes you provide. It's very easy to use on any page as it's an external script, you just call it from your page. I wouldn't use it for any more than about 50 quotes though, it would probably slow your site down too much. Here's the code:
CODE

var ar = new Array(44)
ar[0] = "Do not meddle in the affairs of wizards, for they are subtle and quick to anger."
ar[1] = "Faithless is he that says farewell when the road darkens."
ar[2] = "I cordially dislike allegory in all its manifestations, and always have done since I grew old and wary enough to detect its presence. "
ar[3] = "If more of us valued food and cheer and song above hoarded gold, it would be a merrier world."
ar[4] = "It's a job that's never started that takes the longest to finish."
ar[5] = "Little by little, one travels far."
ar[6] = "I don't know half of you half as well as I should like; and I like less than half of you half as well as you deserve."
ar[7] = "It's a dangerous business going out your front door."
ar[8] = "All that is gold does not glitter."
ar[9] = "His house was perfect, whether you liked food, or sleep, or work, or story-telling, or singing, or just sitting and thinking, best, or a pleasant mixture of them all."
ar[10] = "Many that live deserve death. And some die that deserve life. Can you give it to them? Then be not too eager to deal out death in the name of justice, fearing for your own safety. Even the wise cannot see all ends."
ar[11] = "'I wish life was not so short,' he thought. 'Languages take such a time, and so do all the things one wants to know about.'"
ar[12] = "Still round the corner there may wait, a new road or a secret gate."
ar[13] = "There I lay staring upward, while the stars wheeled over... Faint to my ears came the gathered rumour of all lands: the springing and the dying, the song and the weeping, and the slow everlasting groan of overburdened stone."
ar[14] = "Courage is found in unlikely places."
ar[15] = "Advice is a dangerous gift, even from the wise to the wise."
ar[16] = "The world changes, and all that once was strong now proves unsure."
ar[17] = "All we have to decide is what to do with the time that is given to us."
ar[18] = "The world is indeed full of peril, and in it there are many dark places; but still there is much that is fair; and though in all lands love is now mingled with grief, it grows perhaps the greater."
ar[19] = "But I expect they had lots of chances, like us, of turning back, only they didn't. And if they had, we shouldn't know, because they'd have been forgotten. We hear about those as just went on -- and not all to a good end, mind you; at least not to what folk inside a story and not outside it call a good end."
ar[20] = "The board is set, the pieces are moving. We come to it at last... The great battle of our time."
ar[21] = "The Darkness has begun. There will be no dawn."
ar[22] = "Their plans were improved with the best advice."
ar[23] = "With hope or without hope we will follow the trail of our enemies. And woe to them, if we prove the swifter!"
ar[24] = "Their Oath shall drive them, and yet betray them, and ever snatch away the very treasures that they have sworn to pursue."
ar[25] = "The treacherous are ever distrustful."
ar[26] = "He should not vow to walk in the dark, who has not seen the nightfall."
ar[27] = "Few can foresee whither their road will lead them, till they come to its end."
ar[28] = "It's wisdom to recognize necessity, when all other courses have been weighed, though as folly it may appear to those who cling to false hope."
ar[29] = "For though I do not ask for aid, we need it."
ar[30] = "I have no help to send, therefore I must go myself."
ar[31] = "What do you mean? Do you wish me a good morning, or mean that it is a good morning whether I want it or not; or that you feel good on this morning; or that it is a morning to be good on?"
ar[32] = "He that breaks a thing to find out what it is has left the path of wisdom."
ar[33] = "The deeds will not be less valiant because they are unpraised."
ar[34] = "I sit beside the fire and think of all that I have seen."
ar[35] = "I wish I had never come here, and I don't want to see no more magic."
ar[36] = "The Road goes ever on and on, down from the door where it began."
ar[37] = "It all comes from here, the stench and the peril."
ar[38] = "But only a short way ahead its floor and the walls on either side were cloven by a great fissure, out of which the red glare came, now leaping up, now dying down into darkness; and all the while far below there was a rumour and a trouble as of great engines throbbing and labouring."
ar[39] = "A box without hinges, key, or lid, yet golden treasure inside is hid."
ar[40] = "Go not to the elves for counsel, for they will say both yes and no."
ar[41] = "I am told that I talk in shorthand and then smudge it."
ar[42] = "It does not do to leave a live dragon out of your calculations, if you live near him."
ar[43] = "Not all who wander are lost."
var now = new Date()
var sec = now.getSeconds()
document.write("<table cellspacing='0' cellpadding='0' border='0'>")
document.write("<tr><td><img src='img/scroll_top.gif' width=160 height=37 border=0 alt=''></td></tr>")
document.write("<tr><td background='img/scroll_mid.gif'><table align='center' cellspacing='5' cellpadding='5' border='0'><tr>")
document.write("<td valign='top'><font size=-1><i>" + ar[sec % 44] +"</i></font><font size=-1 color=#800000><p align='right'><b>J.R.R. Tolkien</b></p></font></td></tr></table>")
document.write("</td></tr><tr><td><img src='img/scroll_bot.gif' width=161 height=27 border=0 alt=''></td></tr></table>")

The variables you need to set are the top line "var ar = new Array(44)" 44 is the number of quotes, in this case we start at 0 and go to 43, that's 44 lines. Then of course you need set each of the quote variables "ar[0], ar[1], ar[2]" etc to your quotes.

The "document write" statements format the text and display it on the page. You will want to change the images used in the table to what ever images you want to use.

Copy and paste the code above into a text editor, make your changes and save the file as "quote.js" and then upload it to the server.

To call the script you just need to put this code in your page wherever you want the quotes to appear.
CODE
<script src="quote.js"></script>

This assumes the script is in the the same directory as the page calling the script.

An example of the above script can be seen here. Look in the bottom left corner of the page, reload the page to see a new quote.

Have fun with it! biggrin.gif

Notice from cmatcmextra:
Use [-codebox-] tags when writing long lines of code! This is script - it does not discuss any website - moving out of Website Discussion --> General

Notice from KuBi:
On top of cmats note, warning issued.

 

 

 


Comment/Reply (w/o sign-up)

cmatcmextra
A very nice script but I have a one question and a suggestion:
  1. What happens when the amount of seconds is above 43, does it call ar[0] or display nothing or just use ar[43]?
  2. Wouldn't it be easier to use and better (if I wanted to use more than 60 quotes) to use javascript's Math.random() instead now.getSeconds():

    CODE
    var sec = Math.round(Math.random()*43);


    Where 43 is the amount of array number things used. You can replace 43 with any sized number you like.


Comment/Reply (w/o sign-up)

truefusion
This can be done easier with php.

CODE

<?

$quote = array(
"quote1",
"quote2",
"quote3",
"quote4",
"quote5"
);

$rand = array_rand($quote, 1);

echo "$quote[$rand]";

?>

Comment/Reply (w/o sign-up)

neokid
Awesome script, when I get hosted ill try it, thanks

Comment/Reply (w/o sign-up)

Avalon
I like truefusion's php solution better, it's a lot simpler. I'll use that in the future. All you'd need to do is save it as a php page by itself and then use an 'include' statement wherever you want it on the other page. Good work!

I guess the javascript is handy for when you don't have access to php, but that's not a problem at Trap17. smile.gif

Comment/Reply (w/o sign-up)

wassie
very nice script smile.gif
easy and kinda nice. Good tutorial, easy to understand.

Comment/Reply (w/o sign-up)

thablkpanda
I agree also, nice work bro with the JavaScript. I haven't been such an avid javascript user, so you're cool in my eyes for that.

But yeah, the PHP version is quicker, more reliable, and easier. Glad to see that we can accept superiority when it presents itself biggrin.gif

Just messin, nice work both of you.

Mr. Panda

Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : random, quote, script

  1. [phpbb] Member Last-visit Report Script
    for phpbb2 databases (0)
  2. Php Random Titles
    Learn to create neat-o random titles! (11)
    PHP Random Titles Description Ever wondered how some websites (ex:spoono.com) have those cool-o
    random titles appearing in the title bar? Now you get to learn how to do it using PHP. We will be
    using our knowledge of Variables and Echos in this tutorial. Try It Out Creating the code itself
    is fairly easy. To start, lets create some of our different titles. Code CODE $title =
    "This will be more fun that that time - never mind..."; $title = "Another random title... neat
    eh?"; $title = "I've got wood... in my fire place..."; $title = "More ranom titl....
  3. Background Image Swap Script
    Change a Background Image based on clock time (15)
    Background Image Changer Script To swap the background image from your CSS file according to the
    Server Clock Time. 1.) In your CSS file, add the following rule: CODE body {     background:
    url(time.png); } 2.) Create a "folder" named time.png. 3.) Into the folder, place three images
    named morning.png, day.png, night.png. 4.) Also, in the same folder, create an index.php file and
    copy/paste the following script. CODE $hour = date('H'); if ($hour     $image =
    "morning.png"; } elseif ($hour      $image = "day.png"; } else {      $image = "night.pn....
  4. Image Rotator Script (another One)
    easy to implement (0)
    In case you haven't noticed, I have a different Avatar display on the Forum each time the page
    is refreshed. /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif"
    /> For those of you who might want the script to do that, here is the one I am using: HTML
    $filesp = glob('*.png'); if(empty($filesp)){ echo 'no images found...die br >';
    die(); } else{ foreach ($filesp as $file) { $img_array = trim($file); } } shuffle($img_array);
    //select image at random header("C o n t e n t{dash}t y p e: image/png"); // replace th....
  5. For ... Next Loops And Script Planning
    My Fifth PHP Tutorial (2)
    Be sure to read the other ones. They are located in the TUTORIALS section, and at the time of this
    writing all on the first page. Intro To PHP Tutorial 5 - For ... Next Loops and Planning Scripts
    Released 4/15/07 By Chris Feilbach aka GhostRider Contact Info: E-mail: assembler7@gmail.com AIM:
    emptybinder78 Yahoo: drunkonmarshmellows Website: http://www.ghostrider.trap17.com Before I start
    talking about what wonderful things loops are and all the cool stuff they can do, I want to address
    something first. I was asked about something to write in PHP. There isn't....
  6. Php - Randomize Web Title
    using arrays and the random function (5)
    PHP - Randomize Web Title with the rand function... Define the variables numbers we start at number
    0 CODE $title = "Web title 0"; // Title 0 $title = "Web title 1"; // Title 1 $title =
    "Web title 2"; // Title 2 $title = "Web title 3"; // Title 3 $title = "Web title 4"; // Title 4
    ?> now we use the rand() function to get a randomize the web title. rand(0, 4) means we start at
    0 and end at 4 i can get 0,1,2,3,4 one of those. It depends how many arrays you have CODE //
    get a random number   $randomize = rand(0, 4); // Change four to how many arr....
  7. How To: Ip Configuration Script (win Xp)
    If you travel a lot with your laptop, and need to switch between diff (0)
    How To: IP Configuration Script (win XP) If you travel a lot with your laptop, and need to switch
    between different IP's in different locations, this script is for you. There are many programs
    that handle this task very well, but they cost sometimes pretty big money. This tutorial will show
    you how to make your own IP Configuration Script for free. This script is for a static ip address
    configuration and is based on a little program called "NETSH.EXE" which is supplied with Windows.
    How it works. QUOTE Microsoft Windows XP - Using Netsh Netsh.exe is a....
  8. Php Script To Make A Link List
    From the list of the Directory Files (6)
    Well, it has been a while since I have added anything to the Tutorial Sectiion, so here is another
    script for the members to enjoy. This one creates a list of links from the contents of the directory
    which it is run from. For instance, if you run it from the public_html folder, then all the files
    (not the Directores) are listed and linked so when you click on the link, that file is parsed and
    output to the browser. Here is the code: "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    An XHTML 1.0 Strict Page to List the files in this directory ....
  9. Php Menu Bulding Script And Site Template
    available for download (0)
    A Php Menu-builder Tutorial This Sidebar Menu-builder code and the php scripts are adapted from
    a Tutorial on the Astahost.com Forum titled : CMS101 - Content Management System Design .
    Since the original tutorial's author (vujsa) did such a marvellous job of describing the system
    in the original Topic posting, I will not attempt to explain it here, rather, I invite you to have a
    look at his Topic and learn from it. The Basic tutorial provided coding for developing a table-based
    web-site template which used php includes and embedded data to create a &....
  10. Script To Build A List Of Links
    from filenames and h3 tags (2)
    Another Unordered List Script If you remember this Script , that tutorial was about creating
    an un-ordered list of links from a list of files contained in a Folder which was specifically named
    in the script. This current Tutorial goes several steps beyond that first Tutorial by being able to
    create a list from several folder names and, more importantly, the script reads the list of links
    from a 'flat file' rather than depending on the name of the folder to be hard coded in the
    script. It is only one small step to have the folder names found in a mysql ....
  11. Page Generation Time Script
    A script to tell how long it took to generate (17)
    this is a script used to tell you or visitors how fast your page was generated for the person who is
    viewing it... Ok it is verry simple!! all you have to do is put this script on every page... that
    you want it to be on CODE $starttime = explode(' ', microtime()); $starttime =
    $starttime + $starttime ; ?> and put it before everything on the page, for me i put it right
    underneith the DOCTYPE script which i think is a bloody waste of space to have it on there, but
    anyways.. i put it right below that and it works fine!! now where you want the time it....
  12. Verifying Email Addresses
    Using a simple PHP script (9)
    This simple script will allow you to run some basic checks to make sure that any email address
    entered is actually an email address. There is no guarantee offered that this will stop every single
    fake email address, but it'll provide some protection. Now, the code! First we need to get the
    email address to verify. Here, I get it using POST from an HTML form. CODE //Load email
    address from web form $email = $_POST ; Now, we move on to our first check. Does the text that
    has been entered look like it could be an email address? This check can be performed....
  13. Installing Ndstats!
    The greatest Stats script of all time. (4)
    An example of this script cna be found at http://www.own.tc/ (click enter) This is by far the
    BEST stats script and most sites use it! This is a PHP script and requires you to include files
    (Please... don't do iframes!) DOWNLOAD LINK: GO TO www.ZYMIC.com and go to Php scripts>stats
    scripts> and the current version of NDSTATS. Downlaod it and unzip it! Go to your WWW directory and
    create a folder called "ndstats". Then what you need to do is upload all of your files into that
    folder. You all should know how to do that. Then go to the top of the page(s) you wan....
  14. Ultimate Bbcode Tutorial
    [b ],[ i],[u],[quote ],[img ],smilies (9)
    THIS BBCODE TUTORIAL was found to be copied. -- TUTORIAL EDITED --....
  15. How To Use Trap17 Cgi Formmail
    a built-in script in every hosting (15)
    This tutorial is using TRAP17 hosting's built-in script called cgiemail. There are several
    hundreds of free scripts you can download and install it yourself but why not use what is already
    provided for you, if all you need is a simple submit and data collection? Let's begin. There
    are three things you need to remember: 1) you can rename the file however you'd like 2) two
    files (which I'll name them submitForm.html and template.txt ) must be in the same directory
    3) first two lines in template.txt must EXIST. Write your submitForm.html (where you ....
  16. [php] Simple Newsletter Script
    (17)
    This tutorial will give you the code needed and tell you how to implement it. First off you need to
    create a file called mailing.php this will be the file that processes the adding of emails to the
    list. CODE $email = $_POST ; $file = fopen("mailing.txt", "a"); fwrite($file, "\n" . $email);
    fclose($file); header("Location: mailing_thankyou.php"); ?> Next you need to create a file
    called mailing_thankyou.php , simple a page thanking them for signing up. Now create a file called
    mailing.txt with nothing in it, when uploaded to the server set it writable (c....
  17. Secure The Email Addresses On Your Website!
    Wonderful script and useful! And working (10)
    Just follow the instructions below: /* Secure Email Function by Juan Karlo Aquino de
    Guzman Website: http://www.karlo.ph.tc and http://www.abs-cbn.ph.tc E-mail:
    http://www.karlo.ph.tc/send.php Usage: showEmail("support@microsoft.com",0); OR
    showEmail("support@microsoft.com",1); Types: 0 = ordinary random 1 = more secure random To
    include to a script: include_once("email_secure.php"); */ And here is the code :
    CODE /*     Secure Email Function by Juan Karlo Aquino de Guzman     Website:
    http://www.karlo.ph.tc and http://....
  18. E-mail Mailer Script 0.1
    useful for website visitors (4)
    Are you pissed off when you are putting e-mail in your website, you always get spammers? Well,
    here's the solution. Just change the default variables to anything that you like, etc... follow
    the instructions on the script.. Here it is... hope you like it /smile.gif' border='0'
    style='vertical-align:middle' alt='smile.gif' /> CODE //E-mail Mailer Script 0.1 by Juan
    Karlo de Guzman //FOR TRAP17 ONLY... DEMO VERSION... DO NOT DISTRIBUTE header("Content-type:
    text/html; CHARSET=UTF-8"); $int_rand=mt_rand(1,20); if($int_rand>10) {
    $random_numbers=sha1(mt_ra....
  19. Simple Php Counter Script
    How to make a simple php counter script (2)
    In this tutorial i will explain how to make a simple script writen in PHP...that uses .txt file.
    CODE // script writen by tema $a = fopen ("count.txt", "r"); // 1. $bytes = 4;         $x =
    fread($a, $bytes); // 2. $y=$x + 1;                   // 3. $fp = fopen ("counter/count.txt", "w+");
     // 4. fwrite ($fp, "$y");     // 5. fclose ($fp);                // 6. echo "Posjeta:$y";          
         // 7. ?> 1. selecting a file which the script is going to use for counting visits. 2.
    reading from the script 3. adding 1 to the number in the .txt file. 4. opening....
  20. Email Script/form With Php
    how to make a simple email script using php (37)
    Today, I'm going to show you how to make an email script using PHP and HTML. Most people usually
    put Email me if they want an email link on their site, but there are several cons to this.
    First, it's very inconvenient for those people who use web-based mail such as Yahoo!, Hotmail,
    or Gmail because that darn Micro$oft Outlook program comes up if one accidently click the link.
    Second, you are very suseptible to spam bots because they scan your HTML source code for anything
    with the same pattern as an email address and add it to their database. If you are pre....
  21. Php Guessing Script
    Script game.. (4)
    Here's the guessing script, they guess a number and checks if they are right or wrong.. CODE
    if($action==yes){ //have the number that they are suppose to guess... $guess=14; //end
    if($t_guess==$guess){ print "Good job! Guess was right!"; }else{ print "Guess was wrong! Try
    again!"; } } ?> Thats it /smile.gif' border='0' style='vertical-align:middle'
    alt='smile.gif' /> ....
  22. Php Quiz Script
    Make quizzes for your site. (29)
    Hello all, A little bit back I decided to make a quiz scriptjust out of no where lol. However it
    doesnt do anything special but I am going to make an email mod for it so that it will email results
    to your email address. So here is the basis of it. INSTRUCTIONS: Open a new page in your text
    editor and paste in the following code. CODE $qid = "Quiz ID-00"; ?>
    Username: 1.) Question number one is? Answer1 Answer2 2.) Question number two is?
    Answer1 Answer2 3.) Question number three is? Answer1 Answer2 4.) Question num....
  23. Mail Form (php)
    This is a great email form script. (3)
    save this page as formmail.php Code: QUOTE $MailTo = "your email"; $MailSubject =
    "contact"; $MailHeader = "From: $s1"; $MailSent = "Put here the information you want to be shown
    after the message is sent."; if ($s1 == ""){ echo "You did not put your name ."; } else {
    $MailBody = "Name : $s1\n"; } if ($s2 == ""){ echo "You did not put your E-Mail ."; } else {
    $MailBody .= "Email : $s2\n"; } if ($s3 == ""){ } else { $MailBody .= "Message : $s3\n"; } {
    mail($MailTo, $MailSubject, $MailBody, $MailHeader); echo("$MailSent"); } ?>
    ------------------....
  24. Multiple Admin Login (php)
    This is a script that doesnt requre SQL (3)
    first off make a login.html page Code: QUOTE Admin Login Username: Password:
    then make a check.php page Code: QUOTE $admin1 = "admin1"; // first
    admin username $adm_pass1 = "password1"; // first admin password $admin2 = "admin2"; // second
    admin username $adm_pass2 = "password2"; // second admin password if(($username == $admin1 &&
    $password == $adm_pass1) || ($username == $admin2 && $password == $adm_pass2)){ echo
    "Congratulations " . $_POST . " You may now proceed to the admin area !"; } else { echo "Userna....

    1. Looking for random, quote, script
Similar
[phpbb] Member Last-visit Report Script - for phpbb2 databases
Php Random Titles - Learn to create neat-o random titles!
Background Image Swap Script - Change a Background Image based on clock time
Image Rotator Script (another One) - easy to implement
For ... Next Loops And Script Planning - My Fifth PHP Tutorial
Php - Randomize Web Title - using arrays and the random function
How To: Ip Configuration Script (win Xp) - If you travel a lot with your laptop, and need to switch between diff
Php Script To Make A Link List - From the list of the Directory Files
Php Menu Bulding Script And Site Template - available for download
Script To Build A List Of Links - from filenames and h3 tags
Page Generation Time Script - A script to tell how long it took to generate
Verifying Email Addresses - Using a simple PHP script
Installing Ndstats! - The greatest Stats script of all time.
Ultimate Bbcode Tutorial - [b ],[ i],[u],[quote ],[img ],smilies
How To Use Trap17 Cgi Formmail - a built-in script in every hosting
[php] Simple Newsletter Script
Secure The Email Addresses On Your Website! - Wonderful script and useful! And working
E-mail Mailer Script 0.1 - useful for website visitors
Simple Php Counter Script - How to make a simple php counter script
Email Script/form With Php - how to make a simple email script using php
Php Guessing Script - Script game..
Php Quiz Script - Make quizzes for your site.
Mail Form (php) - This is a great email form script.
Multiple Admin Login (php) - This is a script that doesnt requre SQL

Searching Video's for random, quote, script
See Also,
advertisement


Random Quote Script

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com