Forum Moderators: coopster

Message Too Old, No Replies

Converting Script

Need Help

         

branmh

9:17 pm on Nov 1, 2003 (gmt 0)

10+ Year Member



I have created this script that randomly selects a line from a text file and displays it, but I would like to display all lines from the text file also. How would I go about doing that, with line breaks after each line?


<?php

$path = "/path/to/textfiles";

$getmonth = date("m");
$getday = date("d");

$month = isset($_GET["month"])? $_GET["month"] : "$getmonth";
$day = isset($_GET["day"])? $_GET["day"] : "$getday";

$textfile ="$path/history/$month/$day.dat";

$items = file("$textfile");
$item = rand(0, sizeof($items)-1);
echo $items[$item];
?>

jatar_k

12:24 am on Nov 2, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



since file reads the whole file into an array you can just loop through the array to display it.

foreach ($items as $singleline) { 
echo "<p>",$singleline;
}

branmh

1:13 am on Nov 2, 2003 (gmt 0)

10+ Year Member



Thanks