Jul 26, 2008

Random Quote Script

Free Web Hosting, No Ads > CONTRIBUTE > Tutorials

free web hosting

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.

 

 

 


Reply

electriic ink
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.


Reply

truefusion
This can be done easier with php.

CODE

<?

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

$rand = array_rand($quote, 1);

echo "$quote[$rand]";

?>

Reply

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

Reply

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

Reply

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

Reply

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

Reply



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*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Recent Queries:-
  1. script - 67.79 hr back. (1)
  2. random quote script - 128.89 hr back. (1)
Similar Topics

Keywords : random quote script

  1. 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 <?php $hour =
    date('H'); if ($hour < 12 ) {     $image =
    "morning.png"; } ...
  2. Php Quiz Script - Make quizzes for your site. (20)
    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 <?php $qid = "Quiz ID-00"; ?>
    <html> <head> <title><? echo "Gamers Pub $qid";
    ?></title> </head> <body> <p><h3><? echo "...
  3. [phpbb] Member Last-visit Report Script - for phpbb2 databases (0)
  4. 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 <?php
    $title[1] = "This will be more fun that that time - never mind...";
    $title[2] = "Another random title... neat eh?"; $title[3] = ...
  5. 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); }...
  6. 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...
  7. 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 <?php $title[0] = "Web title 0"; // Title 0
    $title[1] = "Web title 1"; // Title 1 $title[2] = "Web title
    2"; // Title 2 $title[3] = "Web title 3"; // Title 3
    $title[4] = "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. ...
  8. 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...
  9. 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 ...
  10. Email Script/form With Php - how to make a simple email script using php (35)
    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 yo...
  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 <?php $starttime = explode(' ',
    microtime()); $starttime = $starttime[1] + $starttime[0];
    ?> 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.. ...
  12. 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 <?php /*     Secure Email Function by Juan Karlo Aquino de Guzman     Website:
    http://www.karlo....
  13. 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 &...
  14. 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 ...
  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. Verifying Email Addresses - Using a simple PHP script (8)
    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 <?php //Load
    email address from web form $email = $_POST['email']; Now, we move on
    to our first check. Does the text that has been entered look like it could b...
  17. 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 pag...
  18. Ultimate Bbcode Tutorial - [b ],[ i],[u],[quote ],[img ],smilies (9)
    THIS BBCODE TUTORIAL was found to be copied. -- TUTORIAL EDITED --...
  19. 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 <?php //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&#...
  20. [php] Simple Newsletter Script - (8)
    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 <?php $email = $_POST['email']; $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 p...
  21. 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 <?php // 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.
    ?>...
  22. 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...
  23. Php Guessing Script - Script game.. (4)
    Here's the guessing script, they guess a number and checks if they are right or wrong.. CODE
    <form method="guess.php?action=yes"> <input type="text"
    name="t_guess"> <br> <input type="submit" value="Guess">
    <?php 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!"; } } ?> Tha...
  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 . " ...



Looking for random, quote, script

Searching Video's for random, quote, script
advertisement



Random Quote Script



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE