Thread: PHP Question
View Single Post
Old 09-27-2003, 11:16 PM  
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