Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Regarding "last updated"

Posted by torriv (torriv), 18 December 2006
I have to start a new topic...

Sometime i wonder how hard thing can be..

I just pasted your code, and put in my data.. but it didn't work.. there is something strange...

you wrote: $pattern = '\.(html|php|php4)$';

but.. if i change those data to my own.. it wouldn't work.. so i found out that if i take away \. and () it worked... almost.. it did gave me the last updated time, on gallery.. when index was the most recently..

and  when i try to add/delete som of the code to experience a little, it find the most recently page to be ip.txt..... not index.php or linker.php...

here is my code like it is know:

<?php
# Most recently updated file in a directory
# Set up
$dir = "/home/triveran/public_html/.";
$pattern = '(poll|gallery|gjestebok|linker|$)';
$newstamp = 0;
$newname = "";
$dc = opendir($dir);
while ($fn = readdir($dc)) {      
# Eliminate current directory, parent directory      
if (ereg('^\.{1,2}$',$fn)) continue;
# Eliminate other pages not in pattern      
     if (! ereg($pattern,$fn)) continue;      
     $timedat = filemtime("$dir/$fn");      
     if ($timedat > $newstamp) {            $newstamp = $timedat;
                 $newname = $fn;
                             }      }
?>
Hjemmesiden ble sist oppdatert: <?= date("l, j. F Y, H:i:s",$timedat) ?>

that gives me this result: Hjemmesiden ble sist oppdatert: Monday, 18. December 2006, 10:30:29
even if i have change a file under linker...

Just tell me when to shut my mouth..

Posted by admin (Graham Ellis), 18 December 2006
I think , then, that ip.txt is the latest file that has changed  

Your regular expression as written looks for all pages that have names containing the word poll, gallery, gjetesbok or linker in their names, or have a name that has an end. And since every file name has an end, you're matching every file name.

Try

$pattern = '(poll|gallery|gjestebok|linker)';

Posted by torriv (torriv), 18 December 2006
didn't help...
This code that i have paste under gave me this output:

Siden ble sist oppdatert: Sunday, 17. December 2006, 23:32:05
Siden som ble oppdatert da er: linker

but as you probably know.. i have updatet index.php (my very first side) this day.. on the 18th...

File structure:
1. public_html(root) : index.php - My very first side... and om_meg.html - page about me..
2. Gjestebok: index.php - My guestbook page..
2. Linker: Index.php - My lins page..
2. Gallery: index.php - my gallery page...
2. Poll: poll.index - a page that is included on my very first side..

Code:

<?php
# Most recently updated file in a directory
# Set up
$dir = "/home/triveran/public_html/.";
$pattern = '(poll|gallery|gjestebok|linker)';
$newstamp = 0;
$newname = "";
$dc = opendir($dir);
while ($fn = readdir($dc)) {      
# Eliminate current directory, parent directory      
if (ereg('^\.{1,2}$',$fn)) continue;
     # Eliminate other pages not in pattern      
     if (! ereg($pattern,$fn)) continue;      
     $timedat = filemtime("$dir/$fn");      
     if ($timedat > $newstamp) {            $newstamp = $timedat;
                 $newname = $fn;
                             }      }
?>
Siden ble sist oppdatert: <?= date ("l, j. F Y, H:i:s",$timedat)?> <br>
Siden som ble oppdatert da er: <?= $newname ?>

Posted by admin (Graham Ellis), 18 December 2006
1. Is your server also in Norway, or in some other time zone?    The time reported is server time.

2. If you have directories that match the pattern, you'll probably want to add in an extra check to elimiate them.

Posted by torriv (torriv), 18 December 2006
let see..

the directories i have added in pattern, is all the direcotires i have data.. but it seems to me that it won't take the time on my first index.php site, that is the last updated page..

if i do this:
$pattern = '/.(poll|gallery|gjestebok|linker)';

it output this:
Siden ble sist oppdatert: Thursday, 1. January 1970, 01:00:00
Siden som ble oppdatert da er:

if i do this:
$pattern = 'poll|gallery|gjestebok|linker)';

it ouput this:
Siden ble sist oppdatert: Sunday, 17. December 2006, 23:32:05
Siden som ble oppdatert da er: gallery

AND if i do this:
$pattern = '/.|poll|gallery|gjestebok|linker|$';

it ouput this:
Siden ble sist oppdatert: Monday, 18. December 2006, 18:52:10
Siden som ble oppdatert da er: ip.txt

and that date and time is the most updatet one.. BUT again, when i now update a page under a sudirectorie.. such as linker, it won't take that date...

as far as i know, the server is in USA...


Posted by admin (Graham Ellis), 18 December 2006
on 12/18/06 at 17:56:39, torriv wrote:
let see..



$pattern = '/.(poll|gallery|gjestebok|linker)';
containing a /, then any character, then the word poll or gallery of gjestebok or linker
Siden ble sist oppdatert: Thursday, 1. January 1970, 01:00:00
No match - 0 date

$pattern = 'poll|gallery|gjestebok|linker)';
containing poll or gallery or gjestebok or linker)
Siden ble sist oppdatert: Sunday, 17. December 2006, 23:32:05

$pattern = '/.|poll|gallery|gjestebok|linker|$';
containg / but not as the last character, or poll or gallery or gjestebok or linker of (!!) having an end - which all file names do so it matches everything
Siden ble sist oppdatert: Monday, 18. December 2006, 18:52:10

BUT again, when i now update a page under a sudirectorie.. such as linker, it won't take that date...

And that's because your code doesn't look in subdirectories

as far as i know, the server is in USA...
I don't think that's the problem after all, although it could give rise to reports up to 10 hours in error (Norway to Alaska time zone difference)

Suggestions - I could do wonders on regular expressions with you ... and I could throw in some PHP the following day

Posted by torriv (torriv), 18 December 2006
"Suggestions - I could do wonders on regular expressions with you ... and I could throw in some PHP the following day"

i don't understand what u mean about that.. if it has something with money, i rather find the solution another place on the internet..

but i'm really thankfull for the help u have given me so far, even we haven't solve any of my problem yet..

Posted by admin (Graham Ellis), 19 December 2006
On a forum like this, we provide help to people who have specific issues they need help with. It's primarily intended for (and use by) people who have been on training courses that we give - we believe in offering post-course support - but we can and do (willingly) answer similar questions from anyone else who comes along. And we don't carge for such a service.

If you're travelling from - say - Oslo to Stavanger you could walk, and people will help you along the way.  But it would be a very long journey.  Or you could ride by car, by bus, by train - and perhaps you could fly.

Impractical to walk?   Yes, it would be, and with better options available. Using a forum like this to learn the fundamentals of PHP is rather like walking from Oslo to Stavanger - not the most efficient way, and not well suited.  Walking is useful in other contexts, but there's a variety of other ways to make the journey too - you can read books, go through tutorial web sites, attend a course.  And, yes, books and courses cost money - but they make huge sense.

Reading your line of questioning, seeing how you're looking to us to assist with each stage rather than running with our suggestions, I concluded that you're the sort of person who would, indeed benefit from buying yourself a course.  I suspect you've tried the books?  That's fair enough - that's not for everyone.   And would you expect to go down to Forenbo and expect to be given a free flight?  I suspect not ...

I'm happy - very happy - to answer questions from past delegates and others on this forum.  Where it gets to the stage that I honestly belive that it's not the best way forward, I'll suggest alternatives and, I regret, have to ease back on helping out for free.  It's just not a good use of my time (and time costs ME money) to pull your out of one ditch just to find you driving stratight into the next one. Better to read the answers carefully as they'll help you to avoid ditches.

Posted by torriv (torriv), 19 December 2006
I really do understand what you mean. And u made up a good point.

but no, i haven't yet read a book on php, BUT i will, as soon as the christmas is over and the new year begin, and the money get on det + side..

but before that, i will discover by my self on the internet, make changes to php codes i find, like those php codes i got from you, and the ones i trying to modify know...

I'm sorry i have taking you a lot of time with my questining... and, as i said.. i'm really thankfull for the help you have given me...

but i then think i have to look futher, for answers on my problems...

Posted by admin (Graham Ellis), 19 December 2006
Thanks ... and you are welcome to ask occasional and specific questions when you get stuck in the books.    Have a good Christmas

-- Graham

Posted by torriv (torriv), 23 December 2006
Hello again!

I have figured out the code!!! I now only have two problem i will fix,

The first one: If i change a site under the gallery subdirectorie, it output: Gallery
BUT
If I change my startpage.. index... it outputs: index.php..

Do you have any good ideas of how to, for example output: Startpage
?

code:
<?php
# Most recently updated file in a directory
# Set up
$dir = "/home/triveran/public_html/.";
$pattern = 'poll|gallery|gjestebok|linker|index|kontakt|om_meg';
$newstamp = 0;
$newname = "";
$dc = opendir($dir);
while ($fn = readdir($dc)) {      
# Eliminate current directory, parent directory      
if (ereg('^.{1,2}$',$fn)) continue;
     # Eliminate other pages not in pattern      
     if (! ereg($pattern,$fn)) continue;      
     $timedat = filemtime("$dir/$fn");      
     if ($timedat > $newstamp) {            $newstamp = $timedat;
                 $newname = $fn;
                             }      }
                                           
?>

My other problem will come on the other post..

Posted by torriv (torriv), 23 December 2006
i think i found a answer to SOME of my question... about GALLERY and index.php..

it outputs GALLERY, because tha DIRECTORY gallery has change... have i right?

Posted by admin (Graham Ellis), 23 December 2006
Yes, you've added an entry in the directory, I expect, whihc means you've changed the directory.  If you don't want it to report the directory, add an extra check to eliminate directories where you eliminate by pattern

Posted by torriv (torriv), 5 January 2007
Hello again and happy new year!

I have a new code on the same topic:

test.php:
<?php
$files = directoryToArray("./", true);

function directoryToArray($directory, $recursive) {
     $array_items = array();
     if ($handle = opendir($directory)) {
           while (false !== ($file = readdir($handle))) {
                 if ($file != "." && $file != "..") {
                       if (is_dir($directory. "/" . $file)) {
                             if($recursive) {
                                   $array_items = array_merge($array_items, directoryToArray($directory. "/" . $file, $recursive));
                             }
                             $file = $directory . "/" . $file;
                             $array_items[] = preg_replace("/\/\//si", "/", $file);
                       } else {
                             $file = $directory . "/" . $file;
                             $array_items[] = preg_replace("/\/\//si", "/", $file);
                       }
                 }
           }
           closedir($handle);
     }
     return $array_items;
}

foreach ($files as $file) {
if (ereg('^.{1,2}$',$file)) continue;
   $tid = max($tid, filemtime($file));
   $navn = basename($file);
}

        ?>

index.php:

<?php
    include("test.php");
    print date("l, j. F Y, H:i:s", $tid);
    print "<br>";
    print $navn;
?>

This code work like i want.. except of one thing... it updates everytime i press refresh... I go to my ftp to look at the "lasat modified" on the properties on index.php.. but it isn't the same as the output...

Do you have any clue of why it updates everytime i'm pressing refresh the site (F5)?

It also outputs index.php as the file name.. so it will always show index.php, since it updates when a visitor visits my page..


Posted by admin (Graham Ellis), 5 January 2007
Quote:
It also outputs index.php as the file name.. so it will always show index.php, since it updates when a visitor visits my page..


It outputs index.php NOT because it's the latest file to be updated, but because it's the last file to be traversed.  That's because the following code ALWAYS changes $navn whether or not it has updated $tid.

Code:
roreach ($files as $file) {
if (ereg('^.{1,2}$',$file)) continue;
   $tid = max($tid, filemtime($file));
   $navn = basename($file);
}


I'm not sure why the date changes every time you refresh; are you crerating some sort of temporary file elsewhere in your directory tree, or is your site so active that someone else always changes a page between your hits?  In any case, you'll get a far better clue when you know which file really is considered to be the latest.

Posted by torriv (torriv), 6 January 2007
Hello again, i need this code:
Code:
if ($file != "." && $file != ".." && $file != "_notes")


To also filter away .jpg, .png, .txt

how do i write this line then?

And i am in progress to translate all of my homepage into english! So people like you, can understand what stands on my homepage

Posted by admin (Graham Ellis), 6 January 2007
if (! ereg('\.(png|txt|jpg)$',$file)) { ....


Posted by torriv (torriv), 6 January 2007
that didn't work out... can u write the line again but with the rest of the line that i wrote?

Posted by admin (Graham Ellis), 6 January 2007
if ($file != "." && $file != ".." && $file != "_notes" && ! ereg('\.(png|txt|jpg)$',$file)) {

Torriv - you really need to look carefully at code like this and work out what it does for yourself rather than just coming back with "it does not work, please do the next bit for me".   I might happen to be here this morning, but I'm in London tomorrow and Monday ... then on Tuesday - well I'm happy to guide you in the right direction, but you need to pick up the clues and run with them.



This page is a thread posted to the opentalk forum at www.opentalk.org.uk and archived here for reference. To jump to the archive index please follow this link.

3 unpublished comments pending on this page

edit your own (not yet published) comments

© WELL HOUSE CONSULTANTS LTD., 2024: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho