我只是想出如何读取一些文件,但我真的不喜欢它。更好的方法来做到这一点? (在php中读取文件)
我有一些文件名为1.txt,2.txt,3.txt等。我需要阅读并打印最后2个文件。我找到了一种方法来做到这一点,但我希望看到其他方法来做到这一点。
我的方式:
<?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++;
}
?>
谢谢!
我同意@lunky。 – Pawka 2009-08-17 18:38:19
其中一个效率不高 – amr 2009-08-17 19:40:38