Dynamic real-time publishing of news programs, you can automatically arrange the display order according to the release time. A news file consists of a text file stored in a specified directory, and when there is news, the program automatically displays it and arranges it at the very beginning of the page.
<title>News</title>
News
The above describes the release of news with text file implementation of the dynamic real-time publishing news program, including the release of news content, I hope to be interested in PHP tutorial friends helpful.
Include (' locationfilename.php ');function Createur1 ($text) {In the news text file so insert your link${http://mysite.ch}or ${http://mysite.ch|my homepage in}Start working with text files section$s = $text;$a =strstr ($s, ' ${');if ($a) {$b =strstr ($a, '} ');if ($b) {$la =strlen ($a); $ls =strlen ($s);$s =substr ($s, 0, $ls-$la);$a =substr ($a, 2);$LB =strlen ($b); $la =strlen ($a);$a =substr ($a, 0, $la-$lb); $b =substr ($b, 1);$ta =strstr ($a, "|");if ($ta) {$la =strlen ($a); $lt =strlen ($ta);$linktext =substr ($a, $la-$lt + 1);$a =substr ($a, 0, $la-$lt);}else{$linktext = $a;}$s = $s. "". $linktext. "". $b;}}return ($s);}Edit your news file storage directory hereRemember that the news file must be a text file$newspath = "/home/htdocs/test/new/";Set array$newsfile =array ();Set up a directory handle$HD =dir ($newspath);Get all the files and store them in an arraywhile ($filename = $hd->read ()) {$s =strtolower ($filename);if (Strstr ($s, ". txt")) {Detect Latest modification Date$lastchanged =filemtime ($newspath. $filename);$newsfile [$filename]= $lastchanged;}}File sortArsort ($newsfile);Output filefor (Reset ($newsfile); $key =key ($newsfile); next ($newsfile)) {$fa =file ($newspath. $key);$n =count ($FA);Print "
n "; Print "". Date ("D.m.y-h:i:s", $newsfile [$key]). " n "; for ($i =0; $i < $n; $i = $i + 1) { $s =chop ($fa [$i]); $s =htmlspecialchars ($s); $s =createur1 ($s); Print $s. " n "; } Print " |
"; } $HD->close ();?>