06-23-2008, 12:08 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: May 2008
Location: Québec
Posts: 104
Thanks: 10
|
generating an html list
Good day to you all,
The following code read recursively a directory and return the content in a html list.
What I need to do is when the class "fly" is use the </li> tag should be after the the next level, like follow :
PHP Code:
MY WAY <ul class="sub"> <li><a href="http://test.com/test_images.php" class="fly">Gatineau - Ottawa</a></li> <ul> <li><a href="http://test.com/test_images.php" class="">Aylmer</a></li> <li><a href="http://test.com/test_images.php" class="">Gatineau Park - Parc de la Gatineau</a></li> <li><a href="http://test.com/test_images.php" class="">Misc. - Divers</a></li> <li><a href="http://test.com//test_images.php" class="">Nat. Capital of Canada - Capital Nat. du Canada</a></li> </ul> <li><a href="http://test.com/test_images.php" class="fly">Gatineau - Ottawa</a></li> <ul> <li><a href="http://test.com/test_images.php" class="">Aylmer</a></li> <li><a href="http://test.com/test_images.php" class="">Gatineau Park - Parc de la Gatineau</a></li> <li><a href="http://test.com/test_images.php" class="">Misc. - Divers</a></li> <li><a href="http://test.com//test_images.php" class="">Nat. Capital of Canada - Capital Nat. du Canada</a></li> </ul>
</ul>
THE GOOD WAY <li><a href="#nogo11" class="fly">Zoom</a> <ul> <li><a href="#nogo12">35mm to 125mm</a></li> <li><a href="#nogo13">50mm to 250mm</a></li> <li><a href="#nogo14">125mm to 500mm</a></li> </ul> </li>
Now here is my code :
PHP Code:
echo "<ul class=\"sub\">\r"; function dirlist($dir) { $ul = true; $dh = opendir($dir); $isLeaf = true; while (false !== ($file = readdir($dh))) { if ($file == '.' || $file == '..') { $subs = true; continue; } $filed = $file; $file = $dir . '/' . $file; $aHasDirs = array(); $aHasDirs = glob(realpath($file) . '/*', GLOB_ONLYDIR); if (count($aHasDirs) > 0) { $class = 'fly'; $ul = true; } else { $class = ''; $ul = false; } if (is_dir($file)) { $isLeaf = false; echo ' <li><a href="http://test.com/test_images.php?folder=' . $file . '" class="' . $class . '">' . $filed . '</a></li>'; echo "\n"; if (!$isLeaf && $ul) { echo " <ul>\n"; } dirlist($file); if (!$isLeaf && $ul) { echo " </ul>\n"; } } } } dirlist ("Pictures/Pics/Pic-S", false);
echo "</ul>";
Thanks and take care !
__________________
That's why we are not alone on earth... let's build !
|
|
|
|