A series of lectures on setting up a PHP personal website (3)_PHP tutorial

WBOY
Release: 2016-07-21 16:04:20
Original
737 people have browsed it

Three homepage news releases to make updates easier for you (middle)

Last time we made a file header (as for the file tail, please make it yourself, assuming it is tail.php), a function module, now , let’s implement a basic function, that is, dynamic publishing

include("makestr.php";
include("head.php");
$newspath="/announce/"; //Directory of news files stored in text files
$newsfile=array();//Prepare news array
$hd=dir($newspath); //Directory Handle
while($filename=$hd->read()){ //Get all files
$s=strtolower($filename);
if(strstr($s,".txt" )){
//Detect 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, upload your news text to the annouce subroutine of your root directory Directory, you can easily publish news. But the real convenience does not lie in this. For example, when the news becomes outdated, it would be great if the program can automatically delete it without ftp. You can directly write the new announcement online. How convenient. Okay, let’s listen to the explanation next time.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/316028.htmlTechArticleThree homepage news releases, making it easier for you to update (medium) Last time we made a file header (as for the file Tail, please make it yourself, assuming it is tail.php), a function module, now...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template