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 09-27-2003, 10:51 PM   #1
version4
Registered User
 
Join Date: Mar 2003
Posts: 13
PHP Question

I've been using the below php script to randomly take a single line from the file test.txt and insert it into a webpage.

Could someone tell me how I could add a variable X to this script so that I can set it to whatever I want, eg x=5. In this case, the script would take 5 lines from test.txt and insert it into a webpage.

Thanks


<?php
$file = "test.txt";
$file_Content = file($file);

if (count($file_Content) > 0) {
$line = $file_Content[rand(0,count($file_Content)-1)];

echo $line;
}
?>
version4 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2003, 11:14 PM   #2
SicChild
Confirmed User
 
Join Date: Mar 2003
Posts: 365
Quote:
Originally posted by version4
I've been using the below php script to randomly take a single line from the file test.txt and insert it into a webpage.

Could someone tell me how I could add a variable X to this script so that I can set it to whatever I want, eg x=5. In this case, the script would take 5 lines from test.txt and insert it into a webpage.

Thanks


<?php
$file = "test.txt";
$file_Content = file($file);

if (count($file_Content) > 0) {
$line = $file_Content[rand(0,count($file_Content)-1)];

echo $line;
}
?>
5 lines after each other? or each one random?
SicChild is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2003, 11:15 PM   #3
kad
Confirmed User
 
Join Date: Feb 2003
Location: Brisbane, Australia
Posts: 735
PHP Code:

<?php
    $file        
"test.txt";
    
$file_Content    file($file);

    
$j 0;
    
$limit 5;

    while (
$j $limit) {
    
      if (
count($file_Content) > 0)    {
          
$line $file_Content[rand(0,count($file_Content)-1)];
    
      echo 
$line;
      }
      
      
$j++;

  }
?>
Try that. Chances are it will spit out the same line multiple times, but you could get around that with with a few extra lines of code.

Hit me up @ 227230257 and ill help ya if im around
__________________
lol internet.
kad is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2003, 11:16 PM   #4
BigFish
Confirmed User
 
Join Date: Jan 2003
Location: United States of America
Posts: 1,159
Quote:
Originally posted by version4
I've been using the below php script to randomly take a single line from the file test.txt and insert it into a webpage.

Could someone tell me how I could add a variable X to this script so that I can set it to whatever I want, eg x=5. In this case, the script would take 5 lines from test.txt and insert it into a webpage.

Thanks


<?php
$file = "test.txt";
$file_Content = file($file);

if (count($file_Content) > 0) {
$line = $file_Content[rand(0,count($file_Content)-1)];

echo $line;
}
?>

<?php
$x = 5; // Your X variable
$file = "test.txt";
$file_Content = file($file);

if (count($file_Content) > 0) {

for($i=0;$i<$x;$i++){

$line = $file_Content[rand(0,count($file_Content)-1)];

echo $line; }
}
?>

Last edited by BigFish; 09-27-2003 at 11:19 PM..
BigFish is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2003, 11:24 PM   #5
Lane
Will code for food...
 
Join Date: Apr 2001
Location: Buckeye, AZ
Posts: 8,496
$file_Content = file("test.txt");
if (count($file_Content) > 0)
for($i=0;$i<5;$i++)
echo $file_Content[rand(0,count($file_Content)-1)];

short version
__________________
Lane is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2003, 11:35 PM   #6
version4
Registered User
 
Join Date: Mar 2003
Posts: 13
Quote:
Originally posted by BigFish



<?php
$x = 5; // Your X variable
$file = "test.txt";
$file_Content = file($file);

if (count($file_Content) > 0) {

for($i=0;$i<$x;$i++){

$line = $file_Content[rand(0,count($file_Content)-1)];

echo $line; }
}
?>
Bigfish,

Thanks, this works well.

Two things I thought of after running your script.

1. How can I avoid duplicate lines being taken from test.txt. I'd like X number of lines, all are different.

2. How to add a break between the lines of data so that each line of text from test.txt is on it's own line.

Currently the output is as follows:

google yahoo google altavista msn

Would like it as (note there are no duplicates and each is on it's own line):

lycos
google
yahoo
altavista
msn

Thanks
version4 is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 09-27-2003, 11:37 PM   #7
JSA Matt
So Fucking Banned
 
Join Date: Aug 2003
Location: San Diego, CA
Posts: 5,464
That code looks familiar
JSA Matt 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.