Re: Recursive Directory Listing

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, 2008-11-04 at 07:51 -0800, Jim Lucas wrote:
> Joe Schaeffer wrote:
> >> Joe,
> >>
> >> Here is a simplified recursive version of your above statement.
> >>
> >> <?php
> >> $dir = '.';
> >> function displayDir($dir='.') {
> >>        $show = FALSE;
> >>        $results = glob($dir.'/*');
> >>        foreach ( $results AS $entry ) {
> >>                if ( is_dir($entry) && !in_array($entry, array('.', '..')) ) {
> >>                        $dirs[] = $entry;
> >>                        $show = TRUE;
> >>                }
> >>        }
> >>        if ( $show ) {
> >>                echo '<ul>';
> >>                foreach ( $dirs AS $entry ) {
> >>                        echo '<li>', basename($entry);
> >>                        displayDir($entry);
> >>                        echo '</li>';
> >>                }
> >>                echo '</ul>';
> >>        }
> >> }
> >> displayDir($dir);
> >> ?>
> >> Hope this helps
> >> --
> >> Jim Lucas
> > 
> > Excellent, Jim. Thanks very much for your help.
> > 
> > At the risk of straying too far from the original
> > subject/call-for-help, is there a way to flag the *first* time the
> > function runs through a <ul> creation? Though my design doesn't call
> > for it now, I could see the value of styling the first level
> > separately than the sub-directories.
> > 
> > Again, thanks very much!
> > --joe
> > 
> 
> I would say to do that with CSS, not building it into the output.
> 
> <style>
> #navigation ul {
> 	Top level UL
> }
> #navigation ul li {
> 	Top level List Items
> }
> #navigation ul ul {
> 	second/third/etc... ul inside the Top UL
> }
> #navigation ul ul li {
> 	second/third/etc..  List Items
> }
> </style>
> 
> <?php
> 
> echo '<div id="navigation">';
> displayDir('.');
> echo '</div>';
> 
> ?>
> -- 
> Jim Lucas
> 
>    "Some men are born to greatness, some achieve greatness,
>        and some have greatness thrust upon them."
> 
> Twelfth Night, Act II, Scene V
>     by William Shakespeare
> 
> 
This will teach me to read ahead to the end of the thread, I've already
been beaten to the answer!


Ash
www.ashleysheridan.co.uk


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux