So then would this work in php?
given the previus example.

foreach $filename ($files){
     print = "<a href=\"$author/$filename\">$filename</a>";
}


thanks for the help,
nixter

-----------------------------------------------------------
Nick.Stankus
Software Engineer
Logicon/Sterling Federal
402-232-7870
-----------------------------------------------------------
"There are two things that are infinite; Human stupidity and the
universe. And I'm not sure about the universe." - Albert Einstein

----- Original Message ----- 
From: "johnny p." <[EMAIL PROTECTED]>
To: "stankusn" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, February 02, 2001 9:50 AM
Subject: RE: [PHP] Chopping up a comand line return.


| Well, I could update your perl code a bit, and try to help with your php
| question at the same time...
| 
| first of all, i would use he following in perl to avoid the `ls` system
| call:
| 
| **************************************************************
| $some_dir = "/your/dir/to/read/from/$author";
| opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!";
| # sorts last modified time, most recent first, and only returns files in
| the directory
| @files = sort {(stat("$some_dir/$a"))[9] < (stat("$some_dir/$b"))[9]}
| grep { -f "$some_dir/$_" } readdir(DIR);
| closedir(DIR);
| **************************************************************
| 
| so, given the perl version...  here's the php version:
| 
| **************************************************************
| $some_dir = "/your/dir/to/read/from/" . $author;
| $DIR = opendir($some_dir) || die "can't opendir $some_dir: $!";
| while (false!==($file = readdir($DIR))) {
| if (filetype($some_dir . "/" . $file) == "file") {
| $mtime = filemtime ($some_dir . "/" . $file);
| $files[$some_dir."/".$file] = $mtime;
| }
| }
| closedir($DIR);
| 
| asort ($files);
| reset ($files);
| **************************************************************
| 
| PHP's filemtime is equivalent to perl's (stat(<file>))[9], which returns
| the modification time of a file.
| PHP's filetype($file) is equivalent to the grep check in Perl for file
| type of file.
| All the others are identical.
| 
| enjoy,
| 
| johnny p.
| 
| 
| 
| > -----Original Message-----
| > From: stankusn [mailto:[EMAIL PROTECTED]]
| > Sent: Friday, February 02, 2001 9:02 AM
| > To: [EMAIL PROTECTED]
| > Subject: [PHP] Chopping up a comand line return.
| >
| >
| > Here is my problem,
| >
| >   I want to read the contents of a dir, on a linux machine,
| > in proper order
| > according to date (ie. from newest to oldest). My problem is
| > I know how to
| > do it in perl....but not in php. I tried what I use is perl
| > and it doesn't
| > work. Here is what I have that does work.
| >
| > $stuff = `ls -C1t /your/dir/to/read/from/$author/`;  ---works
| >
| > now I want to parse up $stuff to get the 10 or so files names
| > so I can link
| > to them. I just
| > cannot figure out how to do it in php.
| >
| > This is how I would do it in perl/CGI
| >
| > @stuff = same as above
| > foreach $filename (@stuff){
| >     next if $filename !~ /(inc$/i;
| >     print = "<a href=\"$author/$filename\">$filename</a>";
| > }
| >
| > I need something pretty much the same in php...I just don't
| > know why it
| > isn't working quite the same......
| >
| > thanks for your time in advance.,
| >
| > nixter
| >
| > -----------------------------------------------------------
| > Nick.Stankus
| > Software Engineer
| > Logicon/Sterling Federal
| > 402-232-7870
| > -----------------------------------------------------------
| > "There are two things that are infinite; Human stupidity and the
| > universe. And I'm not sure about the universe." - Albert Einstein
| >
| >
| >
| > --
| > PHP General Mailing List (http://www.php.net/)
| > To unsubscribe, e-mail: [EMAIL PROTECTED]
| > For additional commands, e-mail: [EMAIL PROTECTED]
| > To contact the list administrators, e-mail:
| > [EMAIL PROTECTED]
| >
| >


Reply via email to