[PHP] laatste regels van een bestand tonen

Pagina: 1
Acties:

  • Johnny
  • Registratie: December 2001
  • Laatst online: 16:02

Johnny

ondergewaardeerde internetguru

Topicstarter
Dit script toont de laatste regel van een bestandje. In plaats van alleen de laatste regel wordt getoond wil ik het zo maken dat hij de laatste x aantal posts toont (5 ofzo). Ik heb al vanalles met FOR geprobeerd maar kom er maar niet uit. Wie kan me helpen?

---begin---

$data='bestand.txt';
$afile = file($data);
for($num = 0; $num < count($afile); $num++)
{$bfile = explode("|",$afile[$num]);}

echo "<p><b><a href=\"mailto:$bfile[3]\">$bfile[2]</a>: </b> $bfile[7]</p>";

---einde---

$bfile[2] = naam
$bfile[3] = email
$bfile[7] = tekst

Voorbeeld output: "Jantje: ik zeg dit"

Aan de inhoud van de bovenstaande tekst kunnen geen rechten worden ontleend, tenzij dit expliciet in dit bericht is verwoord.


Verwijderd

PHP:
1
2
3
4
5
6
7
8
<?
$data='bestand.txt';
$afile = file($data);
for($num = count($afile) - 5; $num < count($afile); $num++) {
  $bfile = explode("|",$afile[$num]);
  echo "<p><b><a href=\"mailto:$bfile[3]\">$bfile[2]</a>: </b> $bfile[7]</p>"; 
} 
?>

Zoiets?

  • Skinny
  • Registratie: Januari 2000
  • Laatst online: 13-09 23:09

Skinny

DIRECT!

of zoiets ?
PHP:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?
$filename = "bestand.txt";
$file_array = file($data);

rsort($file_array); // SORTEER ARRAY OMGEKEERD (laatste regel eerst)
reset($file_array);

for($num = 0; $num < 6; $num++)
{

$columns = explode("|", $file_array[$num]);} 

echo "<p><b><a href=\"mailto:$columns[3]\">$columns[2]</a>: </b> $columns[7]</p>"; 
}
?>

Hoeft ie niet steeds de hele array door te lopen.

SIZE does matter.
"You're go at throttle up!"