Home  >  Article  >  Backend Development  >  Lecture 3 on setting up a PHP personal website

Lecture 3 on setting up a PHP personal website

WBOY
WBOYOriginal
2016-07-29 08:33:491145browse

Three homepage news releases to make updates easier for you (Part 2)
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 do a basic The realization of the function is dynamic publishing
include("makestr.php";
include("head.php");
$newspath="/announce/"; //Stored in text files Directory of news 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); //Files are sorted 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 handle
include("tail.php");
?>
In this way, upload your news text to the annouce subdirectory of your root directory, and you can easily publish news. But the real convenience does not lie in this, for example. , how nice that the program can automatically delete it when it becomes outdated. It’s so convenient to write new announcements online without using ftp. Okay, let’s listen to the next chapter.

The above has introduced the third series of lectures on setting up a PHP personal website, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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