Many people email wondering how the heck we make the random quotes on the title bar at the main page.
Well, we're finally releasing the secret, and its not as hard as you
think :) Lets write the code to pick a random quote using PHP.
Here is what we have to write in English for the processing:
- Randomize everthing so the same quote doesn't come up.
- Use the preg split
function to select a random text from a file. What we're doing here is
loading the whole text file as one string, and then splitting a string
into an array of quotes, everywhere --Next-- appears, it starts a new
cell on the array.
- Select one of the cells in the array of quotes and print it out.
Here it is in PHP:
<?
srand((double)microtime()*1000000);
$arry_txt=preg_split("/--NEXT--/",join('',file("titles.txt")));
echo$arry_txt[rand(0,sizeof($arry_txt)-1)];
?>
Copy-paste that code at the top wherever you want the random quote to
appear, in the title, in the body, anywhere :) The second part invloves
making the titles.txt. That part is really easy to do. Open up Notepad
and start making random quotes. Separate them by --Next--. Here are
some to start you off:
Chalk Full of Vitamins Good for You
--NEXT--
Iron Chef Rules
--NEXT--
Spoonoholics Anonymous
--NEXT--
Spoono Feed Me
--NEXT--
The Envy of Silverware Everywhere
--NEXT--
Who Let the Spoono Out
Save these and upload them in the same directory as the file with the
code above and you should be set to go. Not too tough was it? Well
thats it folks. I hope it works out for you and if it doesn't, post on
the board and we'll try to help you out.