Session on setting up a personal PHP website (3), Session on setting up a personal PHP website (3), and three homepage news releases make updates easier (medium) we made a file header last time (as for the end of the file, please do it yourself, assuming it is tail. php), a function module. now, let's implement a basic function, that is, dynamic release? Phpinclude ("> <LINKhref =" http: // Three homepage news release, making updates easier (medium)
We made a file header last time (as for the end of the file, please do it yourself, assuming it is tail. php), a function module. now, let's implement a basic function, that is, dynamic release.
Include ("makestr. php ";
Include ("head. php ");
$ Newspath = "/announce/"; // News file directory stored in text files
$ Newsfile = array (); // prepare a News array
$ Hd = dir ($ newspath); // Directory handle
While ($ filename = $ hd-> read () {// get all files
$ S = strtolower ($ filename );
If (strstr ($ s, ". txt ")){
// Check the latest modification date
$ Lastchanged = fileatime ($ newspath. $ filename );
$ Newsfile [$ filename] = $ lastchanged;
}
}
Arsort ($ newsfile); // sort files by time
// Output file
For (reset ($ newsfile); $ key = key ($ newsfile); next ($ newsfile ))
{$ Fa = file ($ newspath. $ key );
$ N = count ($ fa );
Echo"
". Date (" d. m. Y-H: I: s ". $ newsfile [$ key])."
\ N ";
For ($ I = 0; $ I <$ n; $ I = $ I + 1 ){
$ S = chop ($ fa [$ I]); // remove spaces
$ S = htmlspecialchars ($ s );
Print $ s ."
\ N ";
}
}
$ Hd-> close (); // release the handle
Include ("tail. php ");
?>
In this way, you can easily publish news by uploading your news text to the annouce subdirectory in your root directory. But the real convenience is not here. For example, when the news is outdated, the program can automatically delete it. It is convenient to directly write new announcements online without using ftp. Now, let's listen to the next decomposition.