random phrase generator - please help?

  • Kairisika
  • Student
  • Student
  • User avatar
  • Posts: 95
  • Loc: Calgary, Canada

Post 3+ Months Ago

I'm hoping this is the right forum...
does anyone know of a <i>very simple</i> coding to basically put a box on a webpage that every time the page is loaded or refreshed spouts out a phrase from a big list of possible phrases?

My knowledge is severly limited, so it would have to be something that works in basic html, or is a preset code that i can just cut and paste.

If someone knows what kind of thing I could use for this that would be totally awesome - I have no idea if there even is a simple way to do this, but can't hurt to ask...
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

First, rename your html file to .php

second, insert this code where you want the random phrase

NOTE: I haven't actually tested this - I'm just writing it off the top of my head

PHP Code: [ Select ]
 
 
 
<?php
 
 
 
$phrases = array("random phrase 1", "random phrase 2","random phrase 3", "etc. etc.");
 
 
 
echo $phrases[rand(0, count($phrases)-1)];
 
 
 
?>
 
 
 
 
  1.  
  2.  
  3.  
  4. <?php
  5.  
  6.  
  7.  
  8. $phrases = array("random phrase 1", "random phrase 2","random phrase 3", "etc. etc.");
  9.  
  10.  
  11.  
  12. echo $phrases[rand(0, count($phrases)-1)];
  13.  
  14.  
  15.  
  16. ?>
  17.  
  18.  
  19.  
  20.  


replace random phrase 1 and all that with your phrases
  • Kairisika
  • Student
  • Student
  • User avatar
  • Posts: 95
  • Loc: Calgary, Canada

Post 3+ Months Ago

So if i have a file, say "file.html", and i want there to be this little rendom phrase box at the top say, i just make it "file.php", put that bit of code in, and leave the rest the same?

I tried renaming my file to .php, with that in it but when i looked at in in the window it just showed me the source code, and no webpage.
And if i tried putting that code in it ands just leaving it as .html, it just ignored that part.

Do i need to change the opening and closing tags that say html?
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

no, chances are that your server doesn't support PHP, or it is disabled.

What host are you on? Are they free?

If you can't get them to enable it for you, you could write one in javascript but that would require all the phrases to be downloaded onto the users' computer, not just the randomly selected one.

I don't know javascript, so I can't do that for you
  • Kairisika
  • Student
  • Student
  • User avatar
  • Posts: 95
  • Loc: Calgary, Canada

Post 3+ Months Ago

I checked and you're right - I'm with a free server that doesn't support php. For free I guess there's only so much you gcan expect. Thanks though.
  • this213
  • Guru
  • Guru
  • User avatar
  • Posts: 1260
  • Loc: ./

Post 3+ Months Ago

Does your host support Perl CGI scripts?
  • quantumcloud
  • Proficient
  • Proficient
  • User avatar
  • Posts: 456
  • Loc: Dhaka, Bangladesh

Post 3+ Months Ago

How about Javascript? It works everywhere wherever there is a browser. lol

Here is a whole bunch of javascript for random quote generation. No server side scripting like php or perl needed. Use in conjunction with your plain html.

http://javascriptkit.com/script/cutindex15.shtml
  • rjstephens
  • Professor
  • Professor
  • User avatar
  • Posts: 774
  • Loc: Brisbane, Australia

Post 3+ Months Ago

but as I've said before the problem with javascript is that you have to send all the phrases to the browser before one can be randomly picked. If you have a lot of visitors then you have a lot of wasted bandwith.
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

I think sites hosted on a free host are unlikely to have loads of visitors (no offence intended), so the wasted bandwidth will be minimal.

And it's no more bandwidth wasted than most people waste on bloated html table layouts and un-optimised images. In fact significantly less wasted bandwidth.

Also if you are putting the javascript in a separate .js file it will cache.
  • Kairisika
  • Student
  • Student
  • User avatar
  • Posts: 95
  • Loc: Calgary, Canada

Post 3+ Months Ago

as rtm suggested, my site is basically just a host for useless stuff I don't want to clutter up my hard drive, and is accessed rather infrequently by people other than myself, thus I have no worries about bandwidth.

However, if there's a whole bunch of phrases that have to be downloaded onto the computer, will that make it take a long time to load?

Also what do you mean by "if you are putting the javascript in a separate .js file it will cache"? My knowledge is limited to html, and I don't tend to have learned the proper terminology for anything...
  • rtm223
  • Mastermind
  • Mastermind
  • User avatar
  • Posts: 1855
  • Loc: Uk

Post 3+ Months Ago

When you download an html file, that file has dependancies:

images
stylesheets
Javascript
etc..

Any external file that needs to be downloaded separately. Well, whenever you download a file, that file is stored in a temporary directory on your computer (the flie has been cached). If the browser then needs to download the same file again, it doesn't bother with getting it from the remote host, because it remembers that file and can just get it from your harddrive.

Therefore, if your random phrase generator is on every page, and is in a separate file, your computer will store the contents of that file on the HDD and so the user will only download the file once (per visit probably) regardless of the number of pages they vist.

Post Information

  • Total Posts in this topic: 11 posts
  • Users browsing this forum: No registered users and 126 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.