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