Re: code quest
| From: | Kirk Bailey | Date: | Sat, 04 Dec 2010 16:29:35 +0000 |
| Subject: | Re: code quest | ||
| References: | 1 2 3 4 5 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-309847@lists.php.net to get a copy of this message | ||
Now Now, fight nice. We don need no stinkin' @$^*$^(! woids here. :-P
Steve Staples wrote:
On Thu, 2010-12-02 at 10:07 -0500, Daniel P. Brown wrote:damn you Daniel... I was just about to reply with almost the EXACT same answer!!! I think the last example would probably be the best one to use, that way you can still have some directories with the . or - or even the _ in the names, and still be able to display them. Steve ps thanks for saving me type it all out Daniel :) -- end Very Truly yours, - Kirk Bailey, Largo Florida kniht +-----+ | BOX | +-----+ thinkOn Wed, Dec 1, 2010 at 23:13, Kirk Bailey <kbailey@howlermonkey.net> wrote: [snip!]Sure. Change:This will exclude the smileys and cgi-bin and such. If it can be persuaded to read a 1 line description from each subdirectory it could then use THAT as the text in the link, instead of the name. This could be useful in many settings.Can this be improved to exclude anything with a '.' or a '-' in it's name?if (is_dir($d) && $d != '.' && $d != '..') {To:if (is_dir($d) && !preg_match('/[\.\-]/',$d)) {Keep in mind, though, that the change will no longer show anythingthat matches the below either:example.directory example-directory special-images css.filesIn other words, you may instead want to explicitly state whichdirectories to omit, and then drop anything that begins with a dot as well (hidden directories on *NIX-like boxes) like so: <?php $excludes[] = 'cgi-bin'; $excludes[] = 'vti_cnf'; $excludes[] = 'private'; $excludes[] = 'thumbnail'; $ls = scandir(dirname(__FILE__)); foreach ($ls as $d) { if (is_dir($d) && !preg_match('/^\./',basename($d)) && !in_array(basename($d),$excludes)) {echo '<li><a href="'.$d.'">'.$d.'</a><br/>'.PHP_EOL;} } ?> -- </Daniel P. Brown> Dedicated Servers, Cloud and Cloud Hybrid Solutions, VPS, Hosting (866-) 725-4321 http://www.parasane.net/