Re: Order directory output

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

 



i hooked up an spl example; and the files are sorted by name.
also, did you want that <p> inside or outside the <span> w/
class=NormalText, because the opening and closing tags are
mixed up..

<?php
class FileIterator extends FilterIterator {
        public function __construct(Iterator $it) {
                if(!($it instanceof DirectoryIterator)) {
                        throw new LogicException(get_class($it) . ' must be
a DirectoryIterator!');
                }
                parent::__construct($it);
        }

        public function accept() {
                if($this->getInnerIterator()->current()->isFile()) {
                        return true;
                }
        }
}

class TextInfoIterator extends ArrayIterator {
        public function __construct($array, $flags=0) {
                $this->ksort();
                parent::__construct($array, $flags);
        }

        public function current() {
                return '<li>' . parent::current() . '</li>';
        }
}

$fileMatchString = '/.*(\.txt|\.TXT)$/';
$resultData = array();

foreach(new RegexIterator(new FileIterator(new
DirectoryIterator('testDir')), $fileMatchString) as $curAllowedFile) {
        try {
                $theFile = $curAllowedFile->openFile('r');
                $theFile->setFlags(SplFileObject::DROP_NEW_LINE);
                $resultData[$curAllowedFile->getFilename()] =
$theFile->fgets();
                unset($theFile);        // close the file ??
        } catch(RuntimeException $e) {
                // do something here
        }
}
?>
<div class="spstory" style="font-family: Times New Roman, Times,serif;
font-size: 12px; width: 290px;">
        <div style="width: 285px; background-color: #FFFFCC; padding:3px;">
                <span class=\"NormalHeadRed\">Breaking News</span>
                <br />Please check here often for breaking news stories.
        </div>
        <p>
                <span class="NomalText">
                        <ul>
                        <?php foreach(new TextInfoIterator($resultData) as
$curTextData) { ?>
                                <?=$curTextData?>
                        <?php } ?>
                        </ul>
                </span>
        </p>
</div>

-nathan

[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