Session on setting up a PHP personal website (III)

Source: Internet
Author: User
Tags newsfile php website
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.