View Full Version : Script to show random quotes
Ryan Fitton
12-28-2007, 06:56 PM
Hi, i am looking for a script that can display random quotes that i have added. I want the script to display a diferent quote every time the page is refreshed. Help me please.:)
Ryan Fitton
12-28-2007, 09:51 PM
i have seen some written in PHP and some in Javascript but i was thinking if there was someway to use PHP and have it linking to an external file where the qoutes are kept.
Yep, that's fine:
<?php
function random_choice($arr) {
return $arr[rand(0, count($arr) - 1) % count($arr)];
}
print random_choice(file('quotes.txt'));
?>
Ryan Fitton
12-29-2007, 10:38 AM
Thanks a lot :)
Ryan Fitton
12-29-2007, 10:43 AM
Yep, that's fine:
<?php
function random_choice($arr) {
return $arr[rand(0, count($arr) - 1) % count($arr)];
}
print random_choice(file('quotes.txt'));
?>
Sorry i have a little problem, how would i set out the quotes.txt file?
Plaintext or HTML, each quote on a separate line.
Ryan Fitton
12-29-2007, 01:41 PM
can you give me an example please, becasue i have tried a new quote on a new line, but it is not working.:confused:
Master_script_maker
12-29-2007, 02:41 PM
from what i understand, you should open a plain text editor like notepad, each quote should be on a different line, then save it as quotes.txt
"something something something"
"blah blah blah"
"somethingelse somethingelse somethingelse"
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.