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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 06-08-2005, 06:35 PM   #1
Donners
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

?>
But it only displays ONE qoute, I want it to display any number of qoutes of my choice. How can I do this?
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 06:38 PM   #2
Ice
Confirmed User
 
Ice's Avatar
 
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
Ice is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 06:42 PM   #3
Donners
Confirmed User
 
Join Date: Jun 2004
Posts: 689
Yes, and it has one qoute per line.
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 06:47 PM   #4
Ice
Confirmed User
 
Ice's Avatar
 
Join Date: Nov 2002
Location: Sunny California
Posts: 26,053
Quote:
Originally Posted by Donners
Yes, and it has one qoute per line.
hmmm I just set it up on my server and it works fine....

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
Ice is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 06:50 PM   #5
Donners
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?
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 06:53 PM   #6
Rice_Master
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

   }

?>
That'll work.
Rice_Master is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 06:54 PM   #7
Rice_Master
Confirmed User
 
Join Date: Mar 2001
Posts: 1,582
Quote:
Originally Posted by Rice_Master
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

   }

?>
That'll work.
There's a chance of getting the same quote twice with that code though.
Rice_Master is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 06:57 PM   #8
Donners
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
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 07:15 PM   #9
swedguy
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);
?>
swedguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 07:30 PM   #10
Donners
Confirmed User
 
Join Date: Jun 2004
Posts: 689
That only shows a bunch of numbers..
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 06-08-2005, 07:41 PM   #11
swedguy
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>";
?>
swedguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.