Random Weekly Quote Code Question
Posted: Tue Oct 12, 2004 11:20 am
Hi. I am new to this forum. My knowledge of PHP is VERY limited but I somehow manage to get by most of the time (usually by grabbing snippets of other people's code which makes me feel rather bad and inept.) I'd like to really get to know PHP better but the majority of my time is unfortunately preoccupied with graphics instead.
I have a PHP script that pulls random quotes from a text file into a webpage. This works fine. Only problem is that the person that wants this feature incorporated wants these quotes to be selected on a weekly basis instead of every time one refreshes the page.
I guess for that matter, these quotes do not even have to be random but can be sequential as long as it loops at the end. But this would be calling up an entirely different script which I would have no idea a how to code. If someone could help walk me through on these two items (or at least post some code for it), then you would have my utmost gratitude and appreciation.
Thanks,
Chuck
I have a PHP script that pulls random quotes from a text file into a webpage. This works fine. Only problem is that the person that wants this feature incorporated wants these quotes to be selected on a weekly basis instead of every time one refreshes the page.
Code: Select all
<?php
$RANDOM_TXT_FILE = "quotes.txt";
srand((double)microtime()*1000000);
if (file_exists($RANDOM_TXT_FILE)) {
$arry_txt = preg_split("/--NEXT--/", join('', file($RANDOM_TXT_FILE)));
echo $arry_txt[rand(0, sizeof($arry_txt) -1)];
} else {
echo "Error: can't open $RANDOM_IMG_FILE file";
}
?>Thanks,
Chuck