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