![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
php help needed!
I have this simple php script..
Code:
<? $quoteFile = "quotes.txt"; //File holding qoutes $fp = fopen($quoteFile, "r"); //Opens file for read $content = fread($fp, filesize($quoteFile)); $quotes = explode("\n",$content); //Put quotes into array fclose($fp); //Close the file srand((double)microtime()*1000000); // randomize $index = (rand(1, sizeof($quotes)) - 1); //Pick random qoute echo $quotes[$index]; //Print quote to screen ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Nov 2002
Location: Sunny California
Posts: 26,053
|
are all your quotes saved in the quotes.txt file and is that file in the same directory as the random quote file?
__________________
icq 1904905 |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
Yes, and it has one qoute per line.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 | |
Confirmed User
Join Date: Nov 2002
Location: Sunny California
Posts: 26,053
|
Quote:
below is the code I used and an example of the quotes.txt file... index.php <html> <head> <title>Untitled</title> </head> <body> <? $quoteFile = "quotes.txt"; //File holding qoutes $fp = fopen($quoteFile, "r"); //Opens file for read $content = fread($fp, filesize($quoteFile)); $quotes = explode("\n",$content); //Put quotes into array fclose($fp); //Close the file srand((double)microtime()*1000000); // randomize $index = (rand(1, sizeof($quotes)) - 1); //Pick random qoute echo $quotes[$index]; //Print quote to screen ?> </body> </html> quotes.txt lick my balls eat my ass I like paste link to working example of above... http://www.pornfinders.com/quote/index.php
__________________
icq 1904905 |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
It works for me too. Maybe my question wasn't clear but I want to be able to show more then one qoute.
Instead of getting "lick my balls" I want to get "lick my balls" "eat my ass" Or all three qoute if i want to. Any way of specificing how many qoutes it shows? |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Join Date: Mar 2001
Posts: 1,582
|
Code:
<? $howmany = 3; // The number of quotes to display. $quoteFile = "quotes.txt"; //File holding qoutes $fp = fopen($quoteFile, "r"); //Opens file for read $content = fread($fp, filesize($quoteFile)); $quotes = explode("\n",$content); //Put quotes into array fclose($fp); //Close the file For ($i = 0; $i < $howmany; $i++) { srand((double)microtime()*1000000); // randomize $index = (rand(1, sizeof($quotes)) - 1); //Pick random qoute echo $quotes[$index] . "<br>"; //Print quote to screen } ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Confirmed User
Join Date: Mar 2001
Posts: 1,582
|
Quote:
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
Many thanks!
Works perfectly! Should have gone here directly, would have saved me a few hours of googling without any results. Thanks again, you saved my day ![]() |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Confirmed User
Industry Role:
Join Date: Jan 2002
Posts: 7,981
|
Or a shorter version....
Code:
<? $howmany = 3; $quoteFile = "quotes.txt"; $quotesArr = file($quoteFile); $quotes = array_rand($quotesArr, $howmany); print join("<br>", $quotes); ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
That only shows a bunch of numbers..
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Confirmed User
Industry Role:
Join Date: Jan 2002
Posts: 7,981
|
Oops. Fast and wrong ;)
I forgot that it returned the keys and not the values. This one works: Code:
<? $howmany = 3; $quoteFile = "in.log"; $quotesArr = file($quoteFile); $keys = array_rand($quotesArr, $howmany); foreach ($keys as $key) print $quotesArr[$key]."<br>"; ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |