Need a new web host or having a problem with a script? Tips and advice on the best way to design, build and maintain your most valuable asset - your website!

'Tip of the Day' - Displaying random content - How?

tcampbell
Posts: 15
Joined: 14 Apr 07
Trust:

'Tip of the Day' - Displaying random content - How?

How would I go about making a small section of my page display random content, kind of like a 'tip of the day', or 'fact' that changes every so often?
  • 0
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
Either by RSS feed or Cron Job or another script... I am not sure how to set it for every so often.... but I do know how to make it display something random whenever the page loads. If you want that I can get back to you later. Got to go for now!
  • 0
tcampbell
Posts: 15
Joined: 14 Apr 07
Trust:
Thanks Adrian, sounds good. I think something like that would be cool.
  • 0
PremiumMember
chatyak86
Posts: 1085
Joined: 17 Jun 06
Trust:
On your php page put this code

<?php
$textfile ="whatever.txt";

$quotes = file("$textfile");
$quote = rand(0, sizeof($quotes)-1);
echo $quotes[$quote];
?>



(You can rename the .txt file to whatever you want.)

Create a new blank page....... make sure it's BLANK... and save it whatever.txt


In that txt file put words or text you want to appear.... make sure each one is on a new line....


like
this

or like this
and like this
  • 0
tcampbell
Posts: 15
Joined: 14 Apr 07
Trust:
Thanks, Adrian, I'll get to work playing around with that...
  • 0