LemonLimeLucky
06-05-2007, 05: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!
-Lucky
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!):
<?php
$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) != "#") {
$counter++;
}
}
fclose($fh);
list($person,$date,$quote) = split("/", $line);
print "Quote of the Day:\n";
print "Person: $person\n";
print "Date: $date\n";
print "Quote: $quote\n";
?>
<?php
$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
}else{
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.
<?php
$file = 'nameof file.txt';
$array = file($file);
shuffle($array);
echo "$array[0]";
?>
-Lucky
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!):
<?php
$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) != "#") {
$counter++;
}
}
fclose($fh);
list($person,$date,$quote) = split("/", $line);
print "Quote of the Day:\n";
print "Person: $person\n";
print "Date: $date\n";
print "Quote: $quote\n";
?>
<?php
$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
}else{
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.
<?php
$file = 'nameof file.txt';
$array = file($file);
shuffle($array);
echo "$array[0]";
?>