View Full Version : Newbie, I need help

06-05-2007, 06:37 PM
I'm trying to make a php file that puts random quotes on my webpage. I have a txt file full of quotes, and they're all separated by slashes ( / ) but I'm still having trouble. Each day I want a random quote to pop up. You know, like today, a George Washington quote, next day, another quote, etc. Here's what I have so far, I was wondering if anyone could tell me what I need to fix or fill in. Thanks I appreciate it!


Here's my coding so far (I really have no experience in PHP whatsoever, so if this can be explained as simply as possible I'd appreciate it!):

$today_counter = 3;
$fh = fopen("quotes.txt", "r");
$counter = 0;
while (!feof($fh) && $counter < $today_counter) {
$line = fgets($fh, 1024);
if (substr($line,0,1) != "#") {
list($person,$date,$quote) = split("/", $line);
print "Quote of the Day:\n";
print "Person: $person\n";
print "Date: $date\n";
print "Quote: $quote\n";


$textfile = "Includes/Quotes.txt"; //quotes file
if ($quotes = @file("$textfile")) { //don't display errors on file open
echo $quotes[array_rand($quotes)]; //echo a random quote
echo ("default quote"); //if quotes file wasn't found, echo out a default quote

(Something a friend sent me)

set the permisions on your txt file to 777.
$file = 'nameof file.txt';
$array = file($file);
echo "$array[0]";

06-05-2007, 07:28 PM
whats happening or not happening with you current code?

06-06-2007, 04:31 PM
Why not just save yourself some time and use a javascript or similar that means you don't have to re-invent the wheel?

function initBanner() {
if ( !document.getElementById ) return;
// arguments: id, delay (amount of time in milliseconds you linger on each item)
// set up pause onmouseover and resume onmouseout? (boolean)
var ban1 = new dw_Banner('bannerDiv', 4500, true);
// add as many items as you like
ban1.addItem('‘Do what you love and love what your’re doing and you’ll never work another day in your life’ Unknown source');
ban1.addItem('‘If you are not using your smile, your’e like a man with a million dollars in the bank account and no checkbook’ Les Giblin');
ban1.addItem('‘The time is always right to do what is right’ Martin Luther King Jr');
ban1.addItem('‘What lies behind us and what lies before us are tiny matters compared to what lies within us’ Ralph Waldo Emerson');
ban1.addItem('‘Integrity is not a 90 percent thing, not a 95 percent thing, either you have it or you don’t’ Peter Scotese');
ban1.addItem('‘Never, never, never give up’ Winston Churchill');
ban1.addItem('‘You must be the change you wish to see in the world’ Ghandi');
ban1.rotate(); // Begin the rotation
Then add this to the body tag!

<body onLoad="initBanner()" >Add your div wherever!

<div id="bannerDiv" >
‘Never, never, never give up’
Winston Churchill
</div>Now look I did not create this so credit goes to: www.dyn-web.com/bus/terms.html (http://www.dyn-web.com/bus/terms.html)
Check their terms and stuff but I am sure it's ok

Have fun:thumbsup:

06-07-2007, 03:53 AM
nearly there..

$file = 'nameoffile.txt';
$array = file($file);
$quotes = explode('/',$array[0]);
echo $quotes[0];

you may want to remove the lines starting with '#" unless they have a particular purpose ?

06-07-2007, 06:28 AM
$file = file_get_contents('quotes.txt');
$array = explode("/", $file);
$array = array_rand($array, 1);
echo $array[0];