Re: Order directory output

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

 



opendir/readdir does not promise to deliver the files in any
particular order, no matter what it seems to do on any given day...

Put them in an array and sort() if it's a small list of files.

Or use exec and "ls -als" or somesuch for a large list of files.

Or...

glob *might* be documented to do things in a certain order, but I
doubt it.

On Fri, February 8, 2008 4:44 pm, Pastor Steve wrote:
> Hi, thanks for all your help today.
>
> I have the following code and I am trying to order the output.
> Currently it
> seems really random. Can anyone point me in the right direction?
>
> <?php
>
> $dir = "content/current/breaking_news/";
>
> // set pattern
> $pattern = ".txt*|.TXT*";
>
> // open directory and parse file list
> if (is_dir($dir))
> {
> if ($dh = opendir($dir))
> {
>
> //This is the div that contains the wrap around for the breaking news
> section.
> echo "
>     <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>";
>
> // iterate over file list
> while (($filename = readdir($dh)) !== false)
>
> {
>
> // if filename matches search pattern, print it
> if (ereg($pattern, $filename))
>    if(strpos($filename,'.')>0)
>
> {
> $fh = fopen("$dir" . "$filename", "r");
>
>     $filehead = fgets($fh);
>
> fclose($fh);
> echo "
>         <li class=\"bn_bullet\">
>             <a href=\"/breaking_news/$filename\">$filehead</a>
>         </li>";
> }
> }
> echo "
>         </ul><p />
>         </span>
>     </div>";
>
> // close directory
> closedir($dh);
> }
> }
>
> ?>
>
> Thank you,
>
> --
> Steve Marquez
>
>


-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some indie artist.
http://cdbaby.com/from/lynch
Yeah, I get a buck. So?

-- 
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