You could do it reading back to front the way you propose but I think it
will work much better in a proper for loop.
// the number of elements in the array.
$num_lines = count($file);
// the line we want to start the loop at.
if ($num_lines > 10)
$start_line = $num_lines - 10;
else
$start_line = 0;
// loop through the array
for ($i=$start_line; $i<$num_lines; $i++)
{
echo "Line #$i.\n";
//do your work here..
}
Hope that helps. Also please don't spam the list. Check your email program
make sure you're sending out only one copy.
- Kevin
----- Original Message -----
From: "WebDev" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, March 06, 2003 3:24 PM
Subject: [PHP] reading last -n lines array is emty
How to grab the last -n lines from a data file and display the stored data
Only the the last 10 line numbers coming back when I echo $i
How do I get the list($adnr, $user, $date, $listed .... to catch the
datafields
datafile looks like
23|Werner|LastN|Street|etc|etc.|etc||||||
24|Veronika||||
// code start
$file = file("data/ads.data");
for ($i = count($file); $i > count($file) - 10; $i--)
foreach($i as $line) {
list($adnr, $user, $date, $listed, $hlong, $eins, $zwei, $drei, $vier,
$usern, $locst, $locstaa, $locc, $funf, $sech, $email, $Url, $ClassCat,
$ClassCat2, $Headstart, $Headend, $Descrip, $End1, $Endzwei, $End3,
$Endvier, $Endfunf, $Endsech, $Endsieben, $Endacht, $Endne, $dreizwei,
$dreidrei, $dreivier, $dreifunf, $dreisechs ) = split ("\|", $buffer);
print " $i <a
href=\"classifieds.cgi?session_key=&search_and_display_db_button=on&db_id=$a
dnr&query=retrieval\" target=\"_blanko\">$Endzwei $End3</a> <br>";
};
// Code end
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php