When we browse some websites, we often see that some news is just updated soon, if it is manual maintenance, it will be a very tedious job. However, we can use the program to control the implementation of the update operation, things will become very convenient (I am not lazy).
Here, I use PHP to implement this function. The principle is that according to the time of the press release in reverse order, and then on a page display the news connection list, each connection corresponds to a news content page. Here's how:
First, in your site under the establishment of a directory, the edited news pages are saved in this directory, all the news pages in the future are put here, easy to maintain. The News page format is hypertext (don't say you don't have HTML), the first behavior "<HTML> <HEAD> <TITLE> News headlines </TITLE> </HEAD>" (reason is explained later).
Second, write the program, realize the News Automatic Update function (assuming the file name is paixu.php)
The source program is as follows:
<?php
$FP =array ("filename" => "", "Filetime" => "", "Firstline" => "");//Create an array, save the file name, the first line of the file
$dd =dir (' News Save Directory ');//Read the Save directory of the news file
$i = 0;
Clearstatcache ();
while ($file = $dd->read ())//loop to read the files in the directory
{
if (Is_file ($dd->path. /". $file))
{
$fp [$i] [filename]]= $dd->path. " /". $file;//Save file name
$fr =fopen ($dd->path. " /". $file," R ");
$fp [$i] ["Firstline"]=FGETSS ($FR, 60);//Remove HTML tags and save the first line of the file (that is why we want to write the first line of the news page in the required format)
Fclose ($FR);
if ($time =date ("Y m D h:i", Filemtime ($dd->path. " /". $file)))//Save the file time as a sort condition
{
$fp [$i] ["FILETIME"]= $time;
}
$i + +;
}
}
$i =count ($FP);//Save File Number
$i-=4;
for ($j =0; $j $i; $j + +)//According to the bubble algorithm (computer newspaper has an article introduced, I don't wordy)
for ($k = $i; $k > $j; $k-)
if ($fp [$j] ["FILETIME"]<= $fp [$k] ["FILETIME"])
{
$c = $fp [$j] [FILETIME];
$fname = $fp [$j] ["filename"];
$fcontent = $fp ["$j"] ["firstline"];
$fp [$j] ["FILETIME"]= $fp [$k] ["FILETIME"];
$fp [$j] ["filename"]= $fp [$k] ["filename"];
$fp [$j] ["Firstline"]= $fp [$k] ["Firstline"];
$fp [$k] ["FILETIME"]= $c;//line30
$fp [$k] ["filename"]= $fname;
$fp [$k] ["Firstline"]= $fcontent;
}
for ($i =0; $i <= (Count ($fp)-4), $i + +)//Read the saved file information, do the corresponding connection
{
echo "<tr> <td>";
echo "<a Href=". $fp [$i] [filename]. " > ". $fp [$i] [firstline]." </a> ";
echo "</td> <td class=font1>";
echo "(". $fp [$i] ["FILETIME"]. ") <br> \ n ";
echo "</td> </tr>";
}
$dd->close ();
? >
Third, put the program and directory on your website, and then in the browser typing http://directory/panxu.php, can you see?
Finally, a few more words (I do not want to make more money, mainly to serve the serving), your site must support PHP features.
And, I just provide the basic functions, you can add more control functions, as well as the page decoration and landscaping work, it is up to you (what?). Say I'm not responsible for the end? I am bitter ...). All right, let's go. There is something wrong, but also please more advice, you can send email:zbclh@sina.com contact me to communicate.
http://www.bkjia.com/PHPjc/315349.html www.bkjia.com true http://www.bkjia.com/PHPjc/315349.html techarticle when we browse some websites, we often see that some news is just updated soon, if it is manual maintenance, it will be a very tedious job. However, we can pass ...