GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   php help needed! (https://gfy.com/showthread.php?t=478530)

Donners 06-08-2005 06:35 PM

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?

Ice 06-08-2005 06:38 PM

are all your quotes saved in the quotes.txt file and is that file in the same directory as the random quote file?

Donners 06-08-2005 06:42 PM

Yes, and it has one qoute per line.

Ice 06-08-2005 06:47 PM

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

Donners 06-08-2005 06:50 PM

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?

Rice_Master 06-08-2005 06:53 PM

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 06-08-2005 06:54 PM

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.

Donners 06-08-2005 06:57 PM

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 :)

swedguy 06-08-2005 07:15 PM

Or a shorter version....

Code:

<?
$howmany = 3;
$quoteFile = "quotes.txt";
$quotesArr = file($quoteFile);
$quotes = array_rand($quotesArr, $howmany);
print join("<br>", $quotes);
?>


Donners 06-08-2005 07:30 PM

That only shows a bunch of numbers..

swedguy 06-08-2005 07:41 PM

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>";
?>



All times are GMT -7. The time now is 12:26 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123