You to display an arbitrary number of lines from an array, you just need to define that number and then loop through to that number.
$fcontents = file("something.txt");
$display_num_lines = 5;
$actual_num_lines = sizeof($fcontents);
for ($i = 0; $i < $display_num_lines && $i < $actual_num_lines; $i++) {
echo "Line $i: " . htmlspecialchars ($fcontents[$i]) . "<br>\n";
}
You use the for loop to run through the array, which when broken down, does the following:
$i = 0; // Obviously sets i to 0.
$i < $display_num_lines // keep looping through while until we have displayed the number of lines requested
&& $i < $actual_num_lines // This makes sure that we don't overrun our bounds (doesn't really matter in php, but you could get a bunch of nothing if you don't)..
And then you echo it out like you want, but the line number is $i and the actual line is $fcontents[$i]. Hope that helps!
Chris King