Home >Backend Development >PHP Tutorial >Lecture 3 on setting up a PHP personal website
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."
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.