$nbchar - 20) return substr ($str, 0, $pos); else return $str; } // $all: =1 if archive, =0 if summary // $dir: directory where articles are found // $nbchar: max nb of chars to be printed before "See more..." function printarchive ($all, $dir, $nbchar){ if (!is_dir($dir)){ echo "Erreur : " . $dir . " n'est pas un répertoire.
"; exit (); } /* // first method, but the PHP module forbids shell_exec... $files = explode ("\n", shell_exec ("ls -c " . $dir)); */ // second method, where the output needs to be sorted $dh = opendir($dir); if ($dh == false){ echo "Erreur : " . $dir . " ne peut pas être lu.
"; exit (); } while (($file = readdir($dh)) !== false) if ($file != "." && $file != "..") // don't take into account . and .. //$files[$i++] = $file; $files[$file] = filectime ($file); closedir($dh); // sort files by creation time arsort ($files, SORT_NUMERIC); // now, $files contains at least the 5 files to be displayed if ($all != 1){ // print the first 5 articles only echo ""; }else{ // print the archive with all the articles echo "
"; $i = 0; foreach ($files as $file => $val){ if (!ereg("\.html$", $file)) continue; $fcont = file_get_contents ($file); $hlen = strpos (strtolower($fcont), ""); $body = substr ($fcont, $hlen + 6); // strip the text "" too $head = substr (strip_tags ($body), 0, $nbchar); $headwords = trimwordright ($head, $nbchar); $date = date ("d m Y", filectime ($file)); echo "
" . $date . "
" . $headwords . " (lire la suite...)"; $i++; } echo "
"; } if ($i == 0) echo "Aucun article."; } ?>