Hi there, I just figured out how to read some files but I really don't like it.
I have some files named 1.txt, 2.txt, 3.txt and so on. I need to read and print just the last 2 files. I found a way to do it but I would like to see some other ways to do it.
My way:
<?php
$i = 1;
$x = 1;
while (file_exists('news/'.$i.'.txt')){
$i++;
}
$i--;
while ((file_exists('news/'.$i.'.txt')) && ($x <= 2)){
$data = file_get_contents('news/'.$i.'.txt');
echo $data;
$i--;
$x++;
}
?>
Thanks!!