I have a directory full of files with the naming convention of yyyymm.xml I need to generate a list like this:
<ul>
<li>2010
<ul>
<li>Dec</li>
<li>Nov</li>
...
<li>Feb</li>
<li>Jan</li>
</ul>
</li>
<li>2009
<ul>
<li>Dec</li>
...etc.
</ul>
</li>
</ul>
My most recent attempt:
<?php
$tempYear = 0;
date_default_timezone_set('Australia/Melbourne');
if ($handle = opendir('news')) {
// Open the news dir
echo "<p>News archive</p>";
echo "<ul>";
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$fileDate = basename($file, ".xml");
$fileDate = $fileDate . "01";
// Strip the .xml extention from the filename
$currYear = date("Y", strtotime($fileDate));
$currMonth = date("F");
$archMonth = date("F", strtotime($fileDate));
//echo "<li>$archMonth</li>";
if ($currYear != $tempYear){
echo "<li>$currYear";
$tempYear = $currYear;
}else{
echo "<ul>";
while ($currMonth != $archMonth){
echo "<li>$archMonth</li>";
}
echo "</ul>";
echo "</li>";
}
}
}
echo "</ul>";
closedir($handle);
}
?>