Hi i have php which shows me all files in dir and make them href. in the output i have list of files like kpi_03.03.2015.html, kpi_02.03.2015.html etc. I need to sort the output by date for example.
<html>
<head>
<meta http-equiv="Content-Type" content="application/html; charset=utf-8" />
</head>
<body>
<?php
if ($handle = opendir('/opt/nagios/share/kpi_backup')) {
while (false !== ($file = readdir($handle)))
{
if ($file != "." && $file != "..")
{
$thelist .= '<a href="'.$file.'">'.$file.'</a>';
}
}
closedir($handle);
}
echo "list of files:<br><br>";
echo $thelist;
?>
</body>
</html>
I tried lot of variants like:
sort($thelist);
for ($i=0; $i <= 4; $i++)
echo $thelist[$i]."<br \>";
But its not working for me.